USP_DATAFORMTEMPLATE_ADD_CONSTITUENTDATAREVIEWROLLBACK_EMAILADDRESS_DELETE

The save procedure used by the add dataform template "Constituent Data Review Email Address Delete Data Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@EMAILADDRESSID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@CONSTITUENTDATAREVIEWROLLBACKREASONID uniqueidentifier IN Reason

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_CONSTITUENTDATAREVIEWROLLBACK_EMAILADDRESS_DELETE
(
    @ID uniqueidentifier = null output,
    @EMAILADDRESSID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @CONSTITUENTDATAREVIEWROLLBACKREASONID uniqueidentifier = null
)
as

set nocount on;

if @ID is null
    set @ID = newid()

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

declare @CURRENTDATE datetime
set @CURRENTDATE = getdate()

begin try
    exec dbo.USP_EMAILADDRESS_DELETE @EMAILADDRESSID, @CHANGEAGENTID

    declare @AUDITID uniqueidentifier;

    -- pull the auditid for what is hopefully the delete we just did

    select top 1 @AUDITID = AUDITID
    from dbo.EMAILADDRESSAUDIT
    where AUDITRECORDID = @EMAILADDRESSID
    and AUDITTYPECODE = 2
    order by AUDITDATE desc;

    if @AUDITID is null
        raiserror('ERR_COULDNOTFINDAUDIT', 13, 1);

    insert into dbo.CONSTITUENTDATAREVIEWROLLBACK
        (ID, CONTEXTRECORDID, ROLLBACKAUDITID, SOURCEAUDITID, CONSTITUENTDATAREVIEWROLLBACKREASONID, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
    values
        (newid(), @EMAILADDRESSID, @AUDITID, null, @CONSTITUENTDATAREVIEWROLLBACKREASONID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)

end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0