Lock all workflows and descendants using a business rule

cap08
New Contributor II

I'm creating a business rule to automatically lock all workflows and descendants using:  

BRApi.Workflow.Locking.LockWorkflowUnitDescendants(si, wfClusterPk, profileTypeFilter, workflowChannelKey)

but I'm getting the error: 'the item was not found'. I found an example online but it's not working for me. I didn't know what to populate wfClusterPk with so I defined it as (). I'm fairly new to VB.net and appreciate any help with this - thanks! 

 
  Dim wfClusterPk As New WorkflowUnitClusterPk()
  Dim wfChannelKey As Guid = Guid.Empty
 
  BRapi.Workflow.Locking.LockWorkflowUnitDescendants(si, wfClusterPk,     WorkflowProfileTypes.AllProfiles, wfChannelKey)
 
 
1 ACCEPTED SOLUTION

Krishna
Valued Contributor

@cap08  - Here is an example basically it is getting the current WF Profile and locking it using extender rule.

					Dim wfInfo As WorkflowInfo = BRApi.Workflow.Status.GetWorkflowStatus(si,si.WorkflowClusterPk)
	
	Dim A As String = wfInfo.Name
	brapi.ErrorLog.LogMessage(si,A)
	If wfInfo.Locked  Then
		Brapi.ErrorLog.LogMessage(si,"Not Locked")
		
	Else
		'BRApi.Workflow.Locking.LockWorkflowUnit(si,si.WorkflowClusterPk)
		
		
		BRApi.Workflow.Locking.LockWorkflowUnitDescendants(si,si.WorkflowClusterPk,workflowprofiletypes.InputImportChild,si.WorkflowClusterPk.ProfileKey)

		Brapi.ErrorLog.LogMessage(si," Locked")
		
	
End If

 

Thanks
Krishna

View solution in original post

6 REPLIES 6

Krishna
Valued Contributor

@cap08  - Here is an example basically it is getting the current WF Profile and locking it using extender rule.

					Dim wfInfo As WorkflowInfo = BRApi.Workflow.Status.GetWorkflowStatus(si,si.WorkflowClusterPk)
	
	Dim A As String = wfInfo.Name
	brapi.ErrorLog.LogMessage(si,A)
	If wfInfo.Locked  Then
		Brapi.ErrorLog.LogMessage(si,"Not Locked")
		
	Else
		'BRApi.Workflow.Locking.LockWorkflowUnit(si,si.WorkflowClusterPk)
		
		
		BRApi.Workflow.Locking.LockWorkflowUnitDescendants(si,si.WorkflowClusterPk,workflowprofiletypes.InputImportChild,si.WorkflowClusterPk.ProfileKey)

		Brapi.ErrorLog.LogMessage(si," Locked")
		
	
End If

 

Thanks
Krishna

cap08
New Contributor II

I'll give this a try, thank you!

 

 

cap08
New Contributor II

HI Krishna, this works great for one workflow but doesn't lock all of the workflows. Is there a way to loop through all of the workflows?

Krishna
Valued Contributor

@cap08 - Here you go!

'Get the Workflow and Loop through with Text 1 Value
				Dim gTime As String = BRApi.Workflow.General.GetGlobalTime(si)
				Dim scenario As String = "Actual"
				Dim wfClusterPk2 As WorkflowUnitClusterPk = BRApi.Workflow.General.GetWorkflowUnitClusterPk(si, "Total Corporate", scenario, gTime)
				Dim objList As List(Of WorkFlowProfileInfo) = BRApi.Workflow.Metadata.GetRelatives(si, wfClusterPk2, WorkflowProfileRelativeTypes.Descendants, WorkflowProfileTypes.InputImportChild)
			
				'Workflow Information
				Dim wfList As New Dictionary(Of String, WorkFlowProfileInfo)
				Dim wfList1 As New Dictionary(Of String, WorkFlowProfileInfo)
				For Each w As WorkflowProfileInfo In objList
				
Next

 

Thanks
Krishna

cap08
New Contributor II

@Krishna  Thanks! 

cap08
New Contributor II

I found a solution which works for me and have been meaning to add it here in case someone else can use it. I created business rules to lock or unlock workflows depending upon the parameter in the DM step. 

 

Dim gTime = args.NameValuePairs.XFGetValue("lockPeriod")
Dim scenario As String = "Actual"
Dim wfChannelId As Guid = guid.Empty
Dim profileName As String = "your profile name"
Dim wfClusterPk = BRAPi.Workflow.General.GetWorkflowUnitClusterPk(si,profileName,"Actual", gTime)
Dim profileInfos As List(Of WorkflowProfileInfo) = BRApi.Workflow.Metadata.GetRelatives(si, BRAPI.Workflow.General.GetWorkflowUnitClusterPk(si, profileName, scenario, gtime),
WorkflowProfileRelativeTypes.Descendants,
WorkflowProfileTypes.InputImportChild)
 
For Each profileInfo In profileInfos
 
BRApi.Workflow.Locking.LockWorkflowUnit(si, wfClusterPk)
BRapi.Workflow.Locking.LockWorkflowUnitDescendants(si, wfClusterPk, WorkflowProfileTypes.AllProfiles, wfChannelId)
 
Next