UFN_BATCH_ALLOWCOMMITFORUSER

Returns 1 if current user is allowed to commit the batch, the batch is in a state that allows commit and the batch has not been previously committed.

Return

Return Type
bit

Parameters

Parameter Parameter Type Mode Description
@BATCHID uniqueidentifier IN
@CURRENTAPPUSERID uniqueidentifier IN

Definition

Copy


CREATE function dbo.UFN_BATCH_ALLOWCOMMITFORUSER(@BATCHID uniqueidentifier, @CURRENTAPPUSERID uniqueidentifier)
    returns bit
    as
    begin
        declare @allowed bit;
        declare @statuscode tinyint;
        set @statuscode = 0;
        set @allowed = 0;

        --batch state allows commit

        select @allowed=BATCHWORKFLOWSTATE.ALLOWCOMMIT, @statuscode=BATCH.STATUSCODE from dbo.BATCHWORKFLOWSTATE 
            inner join dbo.BATCH on BATCHWORKFLOWSTATE.ID = BATCH.BATCHWORKFLOWSTATEID
            where BATCH.ID = @BATCHID;

        if @allowed = 1 
            --user has access to batch in its current state

            select @allowed=dbo.UFN_SECURITY_APPUSER_GRANTED_BATCHOWNER(@CURRENTAPPUSERID,@BATCHID)

        if @allowed = 1 and @statuscode not in (0, 3)
            --batch already committed

            set @allowed = 0;

        return @allowed;
    end