USP_PROSPECTRESEARCHREQUESTCONSTITUENT_INPROGRESS

Executes the "Prospect Research Request Constituent: In Progress" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being updated.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the update.
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.

Definition

Copy


CREATE procedure dbo.USP_PROSPECTRESEARCHREQUESTCONSTITUENT_INPROGRESS
(
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier,
    @CURRENTAPPUSERID uniqueidentifier
)
as begin


    if @CHANGEAGENTID is null  
        exec dbo.USP_CHANGEAGENT_GETORCREATECHANGEAGENT @CHANGEAGENTID output

    declare @CURRENTDATE datetime
    set @CURRENTDATE = getdate()

    declare @CONSTITUENTID uniqueidentifier
    select @CONSTITUENTID = CONSTITUENTID from dbo.APPUSER where ID = @CURRENTAPPUSERID

    if coalesce((select ASSIGNEDTOID from dbo.PROSPECTRESEARCHREQUESTCONSTITUENT where ID = @ID), '00000000-0000-0000-0000-000000000000') <> @CONSTITUENTID begin
        raiserror('BBERR_PROSPECTRESEARCHREQUEST_NOTASSIGNEE', 13, 1);
        return 1;
    end
    else if (select STATUSCODE from dbo.PROSPECTRESEARCHREQUESTCONSTITUENT where ID = @ID) <> 2 begin
        raiserror('BBERR_PROSPECTRESEARCHREQUEST_BADINPROGRESSSTATE', 13, 1);
        return 1;
    end

    update dbo.PROSPECTRESEARCHREQUESTCONSTITUENT set
        STATUSCODE = 3,
        DATECHANGED = @CURRENTDATE,
        CHANGEDBYID = @CHANGEAGENTID
    where 
        ID = @ID

    return 0;

end