USP_BATCHTEMPLATE_DELETE
Executes the "Batch Template: Delete" record operation.
Parameters
Parameter | Parameter Type | Mode | Description |
---|---|---|---|
@ID | uniqueidentifier | IN | Input parameter indicating the ID of the record being deleted. |
@CURRENTAPPUSERID | uniqueidentifier | IN | Input parameter indicating the ID of the current user. |
@CHANGEAGENTID | uniqueidentifier | IN | Input parameter indicating the ID of the change agent invoking the delete. |
Definition
Copy
CREATE procedure dbo.USP_BATCHTEMPLATE_DELETE
(
@ID uniqueidentifier,
@CURRENTAPPUSERID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier
)
as
set nocount on;
begin try
declare @TEMPLATEUSECODE tinyint;
select @TEMPLATEUSECODE=TEMPLATEUSECODE from dbo.BATCHTEMPLATE where BATCHTEMPLATE.ID = @ID;
if @TEMPLATEUSECODE = 3
raiserror('ERR_DELETE_SYSTEMDEFINEDTEMPLATE', 13, 1);
declare @GRANTED bit
select @GRANTED=dbo.UFN_SECURITY_APPUSER_GRANTED_BATCHTEMPLATE(@CURRENTAPPUSERID, @ID)
if @GRANTED = 0
raiserror('You do not have permission to delete this batch template.', 13, 1);
declare @inuse bit
select top 1 @inuse = 1 from dbo.BATCH where BATCH.BATCHTEMPLATEID = @ID AND STATUSCODE <> 2;
if @inuse = 1
raiserror('This batch template is in use. All associated batches must be deleted before this operation can be performed.', 13, 1);
if exists(select ID from dbo.NETCOMMUNITYTRANSACTIONPROCESSOR where NETCOMMUNITYTRANSACTIONPROCESSOR.BATCHTEMPLATEID = @ID)
raiserror('This batch template cannot be deleted because it is in use as a Blackbaud Internet Solutions transaction processor.', 13, 1);
if exists(select ID from dbo.GENERATETRANSACTIONSPROCESS where GENERATETRANSACTIONSPROCESS.BATCHTEMPLATEID = @ID)
raiserror('This batch template cannot be deleted because it is in use by a generate transaction process.', 13, 1);
declare @ADDFORM uniqueidentifier;
declare @EDITFORM uniqueidentifier;
declare @COMMITADDFORM uniqueidentifier;
declare @COMMITEDITFORM uniqueidentifier;
--declare @CONTEXTVIEWFORM uniqueidentifier;
--declare @CONTEXTEDITFORM uniqueidentifier;
select @ADDFORM=ADDROWDATAFORMINSTANCEID, @EDITFORM=EDITROWDATAFORMINSTANCEID, @COMMITADDFORM=COMMITROWADDDATAFORMINSTANCEID, @COMMITEDITFORM=COMMITROWEDITDATAFORMINSTANCEID
--@CONTEXTVIEWFORM=ROWCONTEXTVIEWDATAFORMINSTANCEID, @CONTEXTEDITFORM=ROWCONTEXTEDITDATAFORMINSTANCEID
from dbo.BATCHTEMPLATE where ID = @ID;
--Cache CONTEXT INFO
declare @contextCache varbinary(128);
set @contextCache = CONTEXT_INFO();
if not @CHANGEAGENTID is null
set CONTEXT_INFO @CHANGEAGENTID;
delete from dbo.BATCH where BATCHTEMPLATEID = @ID and STATUSCODE = 2;
exec dbo.USP_BATCHTEMPLATE_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID
delete from dbo.DATAFORMINSTANCECATALOG where ID = @ADDFORM;
delete from dbo.DATAFORMINSTANCECATALOG where ID = @EDITFORM;
delete from dbo.DATAFORMINSTANCECATALOG where ID = @COMMITADDFORM;
delete from dbo.DATAFORMINSTANCECATALOG where ID = @COMMITEDITFORM;
--we are now just using the default dataform instances for the context view and edit forms, so we do not need to delete these.
--delete from dbo.DATAFORMINSTANCECATALOG where ID = @CONTEXTVIEWFORM;
--delete from dbo.DATAFORMINSTANCECATALOG where ID = @CONTEXTEDITFORM;
--Restore CONTEXT INFO
if not @contextCache is null
set CONTEXT_INFO @contextCache;
end try
begin catch
exec dbo.USP_RAISE_ERROR;
return 1;
end catch
return 0;