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

Davy
Contributor

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 first step is to load data. Our 2nd step will allow users to make manual entries. We don't want users to jump to 2nd step without passing / getting a green light on first step.

It seems like a common request.

Thanks in advance.

1 ACCEPTED SOLUTION

JackLacava
Community Manager
Community Manager

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.

JackLacava_0-1669216901178.png

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

 

View solution in original post

3 REPLIES 3

JackLacava
Community Manager
Community Manager

I think there is a bit of confusion between Workflow steps and profiles.

Steps are parts of a single Workflow Profile. It's what you get at the top of the screen when you select an item from the Workflow tree:

JackLacava_0-1669196825584.png

Those steps are blocked, you cannot proceed unless you complete them in order. Ideally, all your sequence-locked actions should be carried out there - if you can't find a step combination you like in the available choices of Workflow Name, you can always build a custom Dashboard and drop it in there as Workspace.

The items you see on the left tree are not steps, they are Profiles.

JackLacava_1-1669196896498.png

I guess what you want is to stop some of the profiles from executing unless certain conditions have been met. You can achieve that in a few different ways, depending on what those profiles are exactly, although it's not their natural behaviour to be conditioned to each other's status. Again, at worst you can rely on custom Workspaces to execute arbitrary checks.

Happy holidays Jack. You are right- I was trying to lock the multiple profiles under a workflow. e.g. if user fails to load data, she can't continue to enter adjustments in the 2nd profile.

So please tell me how to lock profiles? 

1) Probably using security - but how?

2) Using VB script to turn security on-off ?

JackLacava
Community Manager
Community Manager

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.

JackLacava_0-1669216901178.png

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