USP_DATAFORMTEMPLATE_EDIT_DONORCHALLENGEENCUMBERBUSINESS_2

The save procedure used by the edit dataform template "Update Donor Challenge Business Process Edit Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@CURRENTAPPUSERID uniqueidentifier IN Input parameter indicating the ID of the current user.
@NAME nvarchar(100) IN Name
@SELECTIONID uniqueidentifier IN Selection
@SITEID uniqueidentifier IN Site

Definition

Copy


                    create procedure dbo.USP_DATAFORMTEMPLATE_EDIT_DONORCHALLENGEENCUMBERBUSINESS_2
                    (
                        @ID uniqueidentifier,
                        @CHANGEAGENTID uniqueidentifier = null,
                        @CURRENTAPPUSERID uniqueidentifier,
                        @NAME nvarchar(100),
                        @SELECTIONID uniqueidentifier,
                        @SITEID uniqueidentifier
                    )
                    as
                    begin
                        set nocount on;

                        declare @CURRENTDATE datetime = getdate();

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

                        declare @BUSINESSPROCESSCATALOGID uniqueidentifier = 'f4877be6-6bee-447c-b620-bc90b3996651';

                        begin try

                            if (@SITEID is not null
                            begin
                                if dbo.UFN_SITEALLOWEDFORUSER(@CURRENTAPPUSERID, @SITEID) = 0 
                                begin
                                    raiserror ('BBERR_SITE_NOACCESS',13,1);
                                    return 1;
                                end
                            end

                            update dbo.DONORCHALLENGEENCUMBERPROCESS
                            set
                                NAME = @NAME,
                                SELECTIONID = @SELECTIONID,
                                CHANGEDBYID = @CHANGEAGENTID,
                                DATECHANGED = @CURRENTDATE
                            where ID = @ID

                            update dbo.BUSINESSPROCESSINSTANCE
                            set
                                BUSINESSPROCESSINSTANCE.SITEID = @SITEID,
                                BUSINESSPROCESSINSTANCE.CHANGEDBYID = @CHANGEAGENTID,
                                BUSINESSPROCESSINSTANCE.DATECHANGED = @CURRENTDATE
                            where
                                BUSINESSPROCESSINSTANCE.BUSINESSPROCESSCATALOGID = @BUSINESSPROCESSCATALOGID
                                and
                                BUSINESSPROCESSINSTANCE.BUSINESSPROCESSPARAMETERSETID = @ID
                                and
                                (
                                    BUSINESSPROCESSINSTANCE.SITEID <> @SITEID 
                                    or 
                                    BUSINESSPROCESSINSTANCE.SITEID is null and @SITEID is not null 
                                    or 
                                    BUSINESSPROCESSINSTANCE.SITEID is not null and @SITEID is null
                                );

                        end try
                        begin catch
                            exec dbo.USP_RAISE_ERROR
                            return 1
                        end catch

                        return 0

                    end