USP_DATAFORMTEMPLATE_ADD_BATCH2WORKFLOWSTATE

The save procedure used by the add dataform template "Batch Workflow Status Add Form".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier INOUT The output parameter indicating the ID of the record added.
@NAME nvarchar(200) IN Name
@BATCHWORKFLOWID uniqueidentifier IN Input parameter indicating the context ID for the record being added.
@ALLOWCOMMIT bit IN Allow batch to be committed when in this status
@ISINITIALSTATE bit IN This is the initial status for the workflow
@ALLOWEDIT bit IN Allow batch to be edited in this status
@PERMISSIONS xml IN Specify roles that have access to batches in this status
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@OVERDUEIN tinyint IN Days allowed before batch is overdue
@ENFORCETOTALMATCHING bit IN Only allow commit when projected totals match batch totals

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_ADD_BATCH2WORKFLOWSTATE
(
  @ID uniqueidentifier = null output,
    @NAME nvarchar(200),
    @BATCHWORKFLOWID uniqueidentifier,
    @ALLOWCOMMIT bit = 0,
    @ISINITIALSTATE bit = 0,
    @ALLOWEDIT bit = 1,
    @PERMISSIONS xml = null,
    @CHANGEAGENTID uniqueidentifier = null,    
    @OVERDUEIN tinyint = 0,
  @ENFORCETOTALMATCHING bit = 0
)
as

set nocount on;

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

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

begin try

    if @ISINITIALSTATE = 1 
        begin                                
            if exists(select ID from dbo.BATCHWORKFLOWSTATE where ID <> @ID and BATCHWORKFLOWID = @BATCHWORKFLOWID and ISINITIALSTATE = 1)
                update dbo.BATCHWORKFLOWSTATE set ISINITIALSTATE = 0 where BATCHWORKFLOWID = @BATCHWORKFLOWID
        end

    insert into dbo.BATCHWORKFLOWSTATE (ID, NAME, BATCHWORKFLOWID, ALLOWCOMMIT, ISINITIALSTATE, ALLOWEDIT, OVERDUEIN, ENFORCETOTALMATCHING, ADDEDBYID, CHANGEDBYID, DATEADDED, DATECHANGED)
        values (@ID, @NAME, @BATCHWORKFLOWID, @ALLOWCOMMIT, @ISINITIALSTATE, @ALLOWEDIT, @OVERDUEIN, @ENFORCETOTALMATCHING, @CHANGEAGENTID, @CHANGEAGENTID, getdate(), getdate())




    if not @PERMISSIONS is null
   declare @TTbl table (
   [GRANTORDENY] int,
   [ID] uniqueidentifier,
   [SYSTEMROLEID] uniqueidentifier)

insert into @TTbl select 
    [GRANTORDENY],
    [ID],
    [SYSTEMROLEID] 
from dbo.UFN_BATCHWORKFLOWSTATE_GETSYSTEMROLEPERMISSIONS_FROMITEMLISTXML(@PERMISSIONS)
where [GRANTORDENY] <> 2

    set @PERMISSIONS = (SELECT [GRANTORDENY], [ID], [SYSTEMROLEID]
      FROM @TTbl
      for xml raw('ITEM'),type,elements,root('PERMISSIONS'),BINARY BASE64)


    exec dbo.USP_BATCHWORKFLOWSTATE_GETSYSTEMROLEPERMISSIONS_ADDFROMXML @ID, @PERMISSIONS, @CHANGEAGENTID;



end try
begin catch
    exec dbo.USP_RAISE_ERROR
    return 1
end catch

return 0