USP_DATAFORMTEMPLATE_EDIT_BATCH2COMMITPARAMETERS

The save procedure used by the edit dataform template "Batch Commit Process Parameter Edit Form 5".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@CHANGEAGENTID uniqueidentifier IN Input parameter indicating the ID of the change agent invoking the procedure.
@CREATEOUTPUTIDSET bit IN Create output selection
@OUTPUTIDSETNAME nvarchar(100) IN Selection name
@OVERWRITEOUTPUTIDSET bit IN Overwrite existing selection
@CREATEEXCEPTIONBATCH bit IN Create exception batch
@EXCEPTIONBATCHNAME nvarchar(60) IN Exception batch number
@PURGEBATCH bit IN Delete batch after committing
@VALIDATEBATCH bit IN Validate batch before committing
@CHECKFORDUPLICATERECORDS bit IN Check for duplicate constituents
@CREATECONTROLREPORT bit IN Create control report
@TOTALSMATCH bit IN Totals match
@OVERRIDEBATCHNUMBER bit IN Override
@USENUMBERINGSCHEME bit IN Use numbering scheme

Definition

Copy

CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDIT_BATCH2COMMITPARAMETERS
  (
    @ID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier = null,
    @CREATEOUTPUTIDSET bit,
    @OUTPUTIDSETNAME nvarchar(100),
    @OVERWRITEOUTPUTIDSET bit,
    @CREATEEXCEPTIONBATCH bit,
    @EXCEPTIONBATCHNAME nvarchar(60),
    @PURGEBATCH bit,
    @VALIDATEBATCH bit,
    @CHECKFORDUPLICATERECORDS bit,
    @CREATECONTROLREPORT bit,
    @TOTALSMATCH bit,
    @OVERRIDEBATCHNUMBER bit
    @USENUMBERINGSCHEME bit
    )
as                                
  set NOCOUNT on;

  declare @valid bit;                    

  declare @CURRENTDATE datetime;
  set @CURRENTDATE = getdate();

  begin try

    if @TOTALSMATCH = 0
    begin
      declare @ENFORCETOTALMATCHING bit
      select @ENFORCETOTALMATCHING=BATCHWORKFLOWSTATE.ENFORCETOTALMATCHING
      from dbo.BATCH
        inner join dbo.BATCHWORKFLOWSTATE on BATCHWORKFLOWSTATE.ID = BATCH.BATCHWORKFLOWSTATEID
      where 
        BATCH.ID=@ID

      if @ENFORCETOTALMATCHING = 1
      begin
        raiserror('Projected totals must match batch totals to commit this batch.',13,1);
      end
    end

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

    if @CREATEOUTPUTIDSET = 1
      begin
        select @valid = dbo.UFN_BUSINESSPROCESS_IDSETCANBECREATED(@OUTPUTIDSETNAME);

        if @valid = 0
          raiserror('A Selection with the same name already exists and is associated with a query and cannot be overwritten.  Please select a different Selection name.',13,1);

        if @OVERWRITEOUTPUTIDSET = 0 or @OVERWRITEOUTPUTIDSET is null
          begin
            select @valid=dbo.UFN_BUSINESSPROCESS_IDSETEXISTS(@OUTPUTIDSETNAME);
            if @valid = 1
              raiserror('A Selection with the same name already exists.  Please select a different name or select to overwrite the existing Selection.',13,1);
          end
      end

    if @CREATEEXCEPTIONBATCH = 0
    begin
        declare @REQUIREEXCEPTIONBATCH bit = 0;
        declare @BATCHTEMPLATEID uniqueidentifier;
        select
          @REQUIREEXCEPTIONBATCH = case when SPECXML.exist('declare namespace bbspec="bb_appfx_batchtype";
            /bbspec:BatchTypeSpec[(@RequireExceptionBatch cast as xs:boolean?) eq xs:boolean("true")]
          ') = 1 then 1 else 0 end,
          @BATCHTEMPLATEID = BATCHTEMPLATEID
        from dbo.BATCH
          inner join dbo.BATCHTEMPLATE on BATCHTEMPLATE.ID = BATCH.BATCHTEMPLATEID
          inner join dbo.BATCHTYPECATALOG on BATCHTYPECATALOG.ID = BATCHTEMPLATE.BATCHTYPECATALOGID
        where BATCH.ID = @ID;

        if @REQUIREEXCEPTIONBATCH = 1
        begin
          set @CREATEEXCEPTIONBATCH = 1;
        end
    end


    if (@CREATEEXCEPTIONBATCH = 1) and 
       (@USENUMBERINGSCHEME = 0) and 
       (@EXCEPTIONBATCHNAME is not null or len(@EXCEPTIONBATCHNAME) > 0) and 
       (@OVERRIDEBATCHNUMBER = 0)
    set @EXCEPTIONBATCHNAME = '';




    if (@CREATEEXCEPTIONBATCH = 1) and (@EXCEPTIONBATCHNAME is not null) and (len(@EXCEPTIONBATCHNAME) > 0)
      begin
        declare @exceptionbatchid uniqueidentifier;
        select @exceptionbatchid=dbo.UFN_BATCH_GETIDBYTEMPLATE(@EXCEPTIONBATCHNAME, @BATCHTEMPLATEID);
        if not @exceptionbatchid is null
            raiserror('The exception batch number specified is already in use.',13,1);
      end                                    

    update
      dbo.[BATCH]
    set
      [CREATEOUTPUTIDSET] = @CREATEOUTPUTIDSET,                            
      [OUTPUTIDSETNAME] = @OUTPUTIDSETNAME
      [OVERWRITEOUTPUTIDSET] = @OVERWRITEOUTPUTIDSET,                            
      [CREATEEXCEPTIONBATCH] = @CREATEEXCEPTIONBATCH,
      [EXCEPTIONBATCHNAME] = @EXCEPTIONBATCHNAME,
      [PURGEBATCH] = @PURGEBATCH,
      [CREATECONTROLREPORT] = @CREATECONTROLREPORT,
      [VALIDATEBATCH] = @VALIDATEBATCH,
      [CHECKFORDUPLICATERECORDS] = @CHECKFORDUPLICATERECORDS,
      [OVERRIDE] = @OVERRIDEBATCHNUMBER,
      [CHANGEDBYID] = @CHANGEAGENTID

    where
      [ID] = @ID;
  end try

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

  return 0;