UFN_BBNC_GETOPENBATCHFROMTEMPLATE

Returns the ID of the first open batch created from the specified instance ID.

Return

Return Type
uniqueidentifier

Parameters

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

Definition

Copy


            create function dbo.UFN_BBNC_GETOPENBATCHFROMTEMPLATE
            (
                @BATCHTEMPLATEID uniqueidentifier,
                @CURRENTAPPUSERID uniqueidentifier = null
            ) 
            returns uniqueidentifier
            as begin
                return
                (
                    select top (1)
                        BATCH.ID
                    from
                        dbo.BATCH
                        inner join dbo.BATCHWORKFLOWSTATE on BATCH.BATCHWORKFLOWSTATEID = BATCHWORKFLOWSTATE.ID
                    where
                        BATCH.BATCHTEMPLATEID = @BATCHTEMPLATEID
                        and BATCH.STATUSCODE = 0
                        and BATCH.ORIGINATINGBATCHID is null --TMV 02/27/2007 CR266381-020807 Downloaded transactions should not be added to exception batches

                        and BATCHWORKFLOWSTATE.ISINITIALSTATE = 1 --TMV 04/13/2007 CR266386-020807 Only download transactions into the workflow's initial state.

                        and dbo.UFN_SECURITY_APPUSER_GRANTED_BATCHOWNER(@CURRENTAPPUSERID, BATCH.ID) = 1 -- TMV 03/26/2007 CR268523-022807 Only download transactions into a batch that the current user will be able to access

                    order by
                        BATCH.DATEADDED
                )
            end