Forum Discussion

Marcello's avatar
Marcello
Contributor
3 years ago

Avoid posting journals on different workflows

Hello I have built a workflow structure for a statutory application where every legal entity has is own workflow. In the entity assignment only 1 entity is assigned to the specific workflow. ...
  • EricOsmanski's avatar
    3 years ago

    Hi Marcello - you can create a JournalsEventHandler under Extensibility Rules. Then you can insert this code to restrict submitting journals to Entities assigned to the WF:

    Select Case args.OperationName

    Case Is = BREventOperationType.Journals.SubmitJournal
    'SUBMIT - only allow submitting to WF Entities
    Me.XFR_HandlePosttoWFEntities(si, globals, api, args)

     

    Private Sub XFR_HandlePosttoWFEntities(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As JournalsEventHandlerArgs)
    '------------------------------------------------------------------------------------------------------------
    'Reference Code: XFR_HandlePosttoWFEntities
    '
    'Description: Display a message to the user to not allow journal posting to Entities outside of the WF
    '
    'Usage: Used to alert the journal submitter that they cannot submit to Entities outside of their WF
    '
    'Created By: OS
    '------------------------------------------------------------------------------------------------------------
    Try

    If (args.IsBeforeEvent = True) Then
    Dim jEx As JournalEx = DirectCast(args.inputs(1), JournalEx)
    Dim ExceptionMessage As String = String.Empty
    Dim FailedEntities As New list(Of String)
    Dim lEI As New list(Of Integer)

    For Each ei As WorkflowProfileEntityInfo In BRApi.Workflow.Metadata.GetProfileEntities(si, jEx.Header.Header.WorkflowProfileID)
    lEI.Add(ei.EntityMemberID)
    Next
    If lEI.Count > 0 Then
    For Each li As JournalLineItemEx In jEx.LineItems
    If Not lEI.Contains(li.LineItem.EntityId) Then
    Dim FailedEntity As Member = BRApi.Finance.Members.GetMember(si, DimType.Entity.Id, li.LineItem.EntityId)
    If Not FailedEntities.Contains(FailedEntity.Name) Then
    FailedEntities.add(FailedEntity.Name)
    End If
    End If 'If Not lEI.Contains(li.LineItem.EntityId)
    Next
    If FailedEntities.Count > 0 Then
    If FailedEntities.Count = 1 Then
    ExceptionMessage = "Entity ""E#" & String.Join(",E#",FailedEntities) & """ is not assigned to the current workflow. Please modify the journal to only include valid entities and reload." & vbCrLf
    Else
    ExceptionMessage = "Entities ""E#" & String.Join(",E#",FailedEntities) & """ are not assigned to the current workflow. Please modify the journal to only include valid entities and reload." & vbCrLf
    End If
    End If 'If FailedEntities.Count > 0
    End If 'If lEI.Count > 0
    End If 'If (args.IsBeforeEvent = True)

    Catch ex As Exception
    Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
    End Try
    End Sub