USP_DATAFORMTEMPLATE_ADD_CONSTITUENTDATAREVIEWROLLBACK_ADDRESS_DELETE

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

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@ADDRESSID 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_ADDRESS_DELETE
(
    @ID uniqueidentifier = null output,
    @ADDRESSID 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_ADDRESS_DELETE @ADDRESSID, @CHANGEAGENTID

    declare @AUDITID uniqueidentifier;

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

    select top 1 @AUDITID = AUDITID
    from dbo.ADDRESSAUDIT
    where AUDITRECORDID = @ADDRESSID
    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(), @ADDRESSID, @AUDITID, null, @CONSTITUENTDATAREVIEWROLLBACKREASONID, @CHANGEAGENTID, @CHANGEAGENTID, @CURRENTDATE, @CURRENTDATE)

end try

begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0