USP_BATCHWORKFLOW_DELETE

Executes the "Batch Workflow: Delete" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being deleted.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the delete.

Definition

Copy


CREATE procedure dbo.USP_BATCHWORKFLOW_DELETE
(
    @ID uniqueidentifier,                        
    @CHANGEAGENTID uniqueidentifier
)                    
as 
  set nocount on;

  begin try
    if exists(select ID from dbo.BATCHTEMPLATE where BATCHWORKFLOWID = @ID)
      raiserror('ERR_WORKFLOW_BATCHTEMPLATE', 13, 1);

    declare @CONTEXTCACHE varbinary(128) = context_info();

    if not @CHANGEAGENTID is null
      set context_info @CHANGEAGENTID;

    delete
      BWT
    from
      dbo.BATCHWORKFLOWTASK BWT
    inner join
      dbo.BATCHWORKFLOWSTATE BWS on BWS.ID = BWT.BATCHWORKFLOWSTATEID
    where
      BWT.BATCHWORKFLOWID is null and
      BWS.BATCHWORKFLOWID = @ID;

    delete
      BWT
    from
      dbo.BATCHWORKFLOWTASK BWT
    inner join
      dbo.BATCHWORKFLOWSTATE NBWS on NBWS.ID = BWT.NEXTBATCHWORKFLOWSTATEID
    where
      BWT.BATCHWORKFLOWID is null and
      NBWS.BATCHWORKFLOWID = @ID;

    if not @CONTEXTCACHE is null
      set context_info @CONTEXTCACHE;

    exec dbo.USP_BATCHWORKFLOW_DELETEBYID_WITHCHANGEAGENTID @ID, @CHANGEAGENTID;
  end try
  begin catch
    exec dbo.USP_RAISE_ERROR;
    return 1;
  end catch

  return 0;