USP_PROSPECTRESEARCHREQUESTCONSTITUENT_PENDING

Executes the "Prospect Research Request Constituent: Pending" 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_PENDING (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier,
                        @CURRENTAPPUSERID uniqueidentifier
                    ) as begin
                        set nocount on;

                        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_PROSPECTRESEARCHREQUESTCONSTITUENT_MODIFIERNOTASSIGNEE', 13, 1);
                            return 1;
                        end
                        else if not (select STATUSCODE from dbo.PROSPECTRESEARCHREQUESTCONSTITUENT where ID = @ID) in (2, 3) begin
                            raiserror('BBERR_PROSPECTRESEARCHREQUESTCONSTITUENT_BADSTATEPENDING', 13, 1);
                            return 1;
                        end

                        update dbo.PROSPECTRESEARCHREQUESTCONSTITUENT
                        set
                            STATUSCODE = 1,
                            ASSIGNEDTOID = null,
                            DATECHANGED = @CURRENTDATE,
                            CHANGEDBYID = @CHANGEAGENTID
                        where
                            ID = @ID;

                        exec dbo.USP_PROSPECTRESEARCHREQUESTCONSTITUENT_UNASSIGNEDPENDINGALERT_SEND @CURRENTAPPUSERID, @ID;

                        return 0;
                    end