USP_DATAFORMTEMPLATE_EDIT_APPUSERCONSTITUENTLINK

The save procedure used by the edit dataform template "Application User Constituent Link 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.
@CONSTITUENTID uniqueidentifier IN Constituent ID

Definition

Copy


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

    declare @CURRENTDATE datetime;

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

        set @CURRENTDATE = getdate();

        if @CONSTITUENTID is not null 
            begin
                --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 = @CONSTITUENTID) and (ID <> @ID);
            end

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

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

    return 0;