USP_DATAFORMTEMPLATE_EDIT_CONSTITUENTLINKAPPUSER

The save procedure used by the edit dataform template "Constituent Link to AppUser 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.
@APPUSERID uniqueidentifier IN Application user

Definition

Copy


                CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_CONSTITUENTLINKAPPUSER
                (
                    @ID uniqueidentifier,
                    @CHANGEAGENTID uniqueidentifier = null,
                    @APPUSERID uniqueidentifier
                )
                as
                    set nocount on;

                    declare @CURRENTDATE datetime;

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

                        set @CURRENTDATE = getdate();

                        --Remove any old link because duplicates are not allowed.

                        --Another way to do this would be to make the user remove the old link - but that would be annoying so we do it for them.

                        update
                            dbo.APPUSER
                        set
                            CHANGEDBYID = @CHANGEAGENTID,
                            DATECHANGED = @CURRENTDATE,
                            CONSTITUENTID=NULL
                        where
                            CONSTITUENTID=@ID;

                        update
                            dbo.APPUSER
                        set
                            CHANGEDBYID = @CHANGEAGENTID,
                            DATECHANGED = @CURRENTDATE,
                            CONSTITUENTID=@ID
                        where
                            ID=@APPUSERID;

                        /*  BAL 10.16.06 No longer inserting into STAFF here
                            if not @ID is null
                            if not exists (select ID from dbo.STAFF where ID=@ID)
                                insert into dbo.STAFF
                                (
                                    ID,
                                    ADDEDBYID,
                                    CHANGEDBYID,
                                    DATEADDED,
                                    DATECHANGED
                                )
                                values
                                (
                                    @ID,
                                    @CHANGEAGENTID,
                                    @CHANGEAGENTID,
                                    @CURRENTDATE,
                                    @CURRENTDATE
                                );
                        */

                    end try
                    begin catch
                        EXEC dbo.USP_RAISE_ERROR;
                        return 1;
                    end catch

                    return 0;