USP_PROSPECTRESEARCHREQUEST_ACCEPT

Executes the "Prospect Research Request: Accept" 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_PROSPECTRESEARCHREQUEST_ACCEPT
(
    @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 dbo.UFN_CONSTITUENT_ISFUNDRAISER(@CONSTITUENTID) = 1 begin
        update
            dbo.PROSPECTRESEARCHREQUEST
        set
            STATUSCODE = 3,
            ASSIGNEDTOID = @CONSTITUENTID,
            CHANGEDBYID = @CHANGEAGENTID,
            DATECHANGED = @CURRENTDATE
        where
            ID = @ID and STATUSCODE in(1, 2, 3)

        update
            dbo.PROSPECTRESEARCHREQUESTCONSTITUENT
        set
            ASSIGNEDTOID = @CONSTITUENTID,
            CHANGEDBYID = @CHANGEAGENTID,
            DATECHANGED = @CURRENTDATE
        where
            PROSPECTRESEARCHREQUESTID = @ID and STATUSCODE in(1, 2, 3) and coalesce(ASSIGNEDTOID, '00000000-0000-0000-0000-000000000000') = '00000000-0000-0000-0000-000000000000'

    end
    else begin
        raiserror('To accept a prospect research request the current user must be linked to an individual constituent record and have a Fundraiser constituency.', 13, 1);
        return 1;
    end

    return 0;

end