Forum Discussion

Davy's avatar
Davy
Contributor
3 years ago

How to lock downstream steps in a workflow, unless the first step in workflow is complete?

Happy Holidays/ Black Friday, Is there a way to lock downstream steps in a workflow, unless the first step in workflow is completed? As we all know, a workflow shows all the steps. For example, our...
  • JackLacava's avatar
    3 years ago

    There are various strategies to address this, depending on the actual profiles, but here is a generic one.

    First, you ensure everything is locked except the prerequisite step. You can do that with the Batch functionality that you find at the top of the tree, just select what you need and click Execute Batch.

    Then, create a Workflow Event Handler that will fire on completion of our prerequisite Profile, unlocking the target profile. This is an example, unlocking Forms only if Import has been completed:

    Dim returnValue As Object = args.DefaultReturnValue
    args.UseReturnValueFromBusinessRule = True
    args.Cancel = False
    Select Case args.operationName
    Case Is = BREventOperationType.Workflow.UpdateWorkflowStatus
    	' work only after updates
    	If args.isBeforeEvent = False Then
    		
    		' Retrieve info from event. 
    		' Check page "Event Firing Sequences" in design & ref guide to know what to cast to
    		Dim wfWf As WorkflowInfo = DirectCast(args.Inputs(0), WorkflowInfo)
    		Dim wfStep As StepClassificationTypes = DirectCast(args.Inputs(1), StepClassificationTypes)
    		Dim wfStatus As WorkflowStatusTypes = DirectCast(args.inputs(2), WorkflowStatusTypes)
    		Dim wfProfileInfo As WorkflowProfileInfo = BRApi.Workflow.Metadata.GetProfile(si, _
    			si.WorkflowClusterPk.ProfileKey)
    		Dim wfParentInfo As WorkflowProfileInfo = BRApi.Workflow.Metadata.GetProfile(si, _
    			wfProfileInfo.ParentProfileKey)
    		
    		' check if we're dealing with the prerequisite profile
    		Dim prereqProfile = "MyBaseInputProfile.Import"
    		If wfProfileInfo.Name.XFEqualsIgnoreCase(prereqProfile) Then
    
    			' if the full workflow is done...
    			If wfWf.AllTasksCompleted Then
    
    				' define the target profile we want to unlock
    				Dim scenarioName As String = brapi.Finance.members.GetMemberName(si, _
    					Dimtype.Scenario.Id, wfWf.WfUnitPk.ScenarioKey)
    				Dim timeName As String = brapi.Finance.Time.GetNameFromId(si, wfwf.WfUnitPk.TimeKey)
    				Dim wfTargetName As String = $"{wfParentInfo.Name}.Forms"
    				Dim wfClusterPk As WorkflowUnitClusterPk = _
    					BRApi.Workflow.General.GetWorkflowUnitClusterPk(si, _
    						wfTargetName, _
    						scenarioName, _ 
    						timeName)
    				' boom
    				BRApi.Workflow.Locking.UnlockWorkflowUnit(si, wfClusterPk)
    				
    			End If
    		End If
    	End If
    	
    End Select