USP_BATCH_MAKEACTIVE

Executes the "Batch: Make active" record operation.

Parameters

Parameter Parameter Type Mode Description
@ID uniqueidentifier IN Input parameter indicating the ID of the record being updated.
@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 update.

Definition

Copy


CREATE procedure dbo.USP_BATCH_MAKEACTIVE
(
    @ID uniqueidentifier,
    @CURRENTAPPUSERID uniqueidentifier,
    @CHANGEAGENTID uniqueidentifier
)
with execute as owner
as 
set nocount on;

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

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

    declare @GRANTED bit
    select @GRANTED=dbo.UFN_SECURITY_APPUSER_GRANTED_BATCHPROCESSOR(@CURRENTAPPUSERID, @ID)
    if @GRANTED = 0
        raiserror('You do not have permission to update this batch template.', 13, 1);

    --mark batch design as active

    update dbo.BATCHTEMPLATE 
  set ACTIVE = 1,
    CHANGEDBYID = @CHANGEAGENTID,
    DATECHANGED = @CURRENTDATE
  where ID = @ID;

  --now that we are active again, reload the spec. The BatchTypeSpecProcessor.UpdateBatchTemplates() will update all templates now.

  declare @BATCHTYPECATALOGID uniqueidentifier
  select @BATCHTYPECATALOGID = BATCHTYPECATALOGID from dbo.BATCHTEMPLATE where ID = @ID
  declare @SPECXML xml
  select @SPECXML = SPECXML from dbo.BATCHTYPECATALOG where ID = @BATCHTYPECATALOGID
  exec dbo.USP_LOADSPEC @SPECXML, @CHANGEAGENTID, null, null, 0, 1 --force reload 


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

return 0;