USP_DATAFORMTEMPLATE_EDITSAVE_BATCHDESIGN

The save procedure used by the edit dataform template "Batch Design Edit".

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN The input ID parameter indicating the ID of the record being edited.
@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 procedure.
@CREATECUSTOMBATCH bit IN Create custom batch
@BATCHFIELDS xml IN Batch fields

Definition

Copy


CREATE procedure dbo.USP_DATAFORMTEMPLATE_EDITSAVE_BATCHDESIGN(
@ID uniqueidentifier,
@CURRENTAPPUSERID uniqueidentifier,
@CHANGEAGENTID uniqueidentifier = null,
@CREATECUSTOMBATCH bit,
@BATCHFIELDS xml
)
as
begin
    set nocount on;

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

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

    declare @TEMPLATEID uniqueidentifier;    
    declare @BATCHTYPECATALOGID uniqueidentifier;
    declare @BATCHWORKFLOWID uniqueidentifier;
    declare @NAME nvarchar(100);

    declare @CUSTOM bit;
    set @CUSTOM = 0;    

    select @TEMPLATEID = BATCHTEMPLATE.ID, @BATCHTYPECATALOGID = BATCHTEMPLATE.BATCHTYPECATALOGID, @NAME = BATCHTEMPLATE.NAME, @BATCHWORKFLOWID = BATCHTEMPLATE.BATCHWORKFLOWID, @CUSTOM = BATCHTEMPLATE.CUSTOM from dbo.BATCHTEMPLATE inner join dbo.BATCH on BATCHTEMPLATE.ID = BATCH.BATCHTEMPLATEID where BATCH.ID = @ID;

    if @CREATECUSTOMBATCH = 1
    begin        
        declare @HASSECURITY bit;
        select @HASSECURITY = dbo.UFN_SECURITY_APPUSER_GRANTED_BATCHTEMPLATECUSTOMIZE(@CURRENTAPPUSERID, @TEMPLATEID)
        if @HASSECURITY = 0
        begin
            raiserror('You do not have permission to create a custom batch from this batch template.', 13, 1);
        end;
        set @TEMPLATEID = newID();
        select @NAME = BATCH.BATCHNUMBER from dbo.BATCH where BATCH.ID = @ID;
        if exists(select top 1 NAME from dbo.BATCHTEMPLATE where NAME = @NAME)
        begin
            --make name unique?

            set @NAME = @NAME + ' ' + convert(nvarchar, GETUTCDATE(), 20);
        end;
        exec dbo.USP_BATCHTEMPLATEPROCESSOR_CREATEORUPDATE @TEMPLATEID output, @BATCHTYPECATALOGID, @NAME, '', @BATCHFIELDS, @BATCHWORKFLOWID, @CHANGEAGENTID, @CREATECUSTOMBATCH;
    end;
    else
    begin        
        if @CUSTOM = 1
            exec dbo.USP_BATCHTEMPLATEPROCESSOR_CREATEORUPDATE @TEMPLATEID output, @BATCHTYPECATALOGID, @NAME, '', @BATCHFIELDS, @BATCHWORKFLOWID, @CHANGEAGENTID, @CUSTOM;            
    end;

    update dbo.BATCH set 
        BATCHTEMPLATEID = @TEMPLATEID
        FORMDEFINITIONXML = @BATCHFIELDS,
        CHANGEDBYID = @CHANGEAGENTID,
        DATECHANGED = @CHANGEDATE
    where BATCH.ID = @ID;

end