No Calculate Rule running on all workflow steps

Richard_Mayo
New Contributor III

Hi Everyone,

I've written a business rule that peforms a certain task when the process button is clicked in the workflow via the "No Calculate" function within the calculation definitions of the workflow profile (see reference (1) in the screenshot). Broadly speaking it works ok, however I intended for it to only be triggered when clicking process on the "top" node of the workflow (see reference (2) in the screenshot).

In actual fact it's running when process button is clicked in any of child workflow step (eg. "Asset Movement" in the example here, see reference (3) in the screenshot).

So my question is: can I have a business rule that is triggered by the No Calculate function but only in certain steps within the workflow? Or will it trigger wherever process is clicked? I had thought it would be possible because calculation definitions can be defined in each workflow step which is why I was surprised with the above.

(By the way calculation definitions are blank in the "Asset Movement" step).

What am I missing?!!!

Thanks for any ideas!

Richard

Richard_Mayo_0-1718206771144.png

 

2 ACCEPTED SOLUTIONS

FredLucas
Contributor II

Hi @Richard_Mayo,

You'll hopefully find the answer to your question on the above options given by @aformenti.

However, if that's not the case, or you need something a little bit more dynamic / custom, here is another option you could explore: 

As you probably know OS does not trigger sequences on No Calculate by default, that sequence is triggered via a custom function defined as part of the DataQualityEventHandler.

Having said that, you could update this custom function (that triggers the sequences defined on the No Calculate) to only trigger it if a certain criteria is met. The criteria could be for example: if the Workflow step is a base step or of a certain type, if there's a specific Text property defined, if it follows a specific naming convention, if the name matches the one passed on as a parameter, etc, etc.

View solution in original post

aformenti
Contributor II

That's a good idea @Fred

See below a screenshot of an slide explaining what Fred means:

aformenti_0-1718266629170.png

The code would be something like this:

#Region "ProcessCube.NoCalculate Helpers"
		Private Sub OSB_HandleProcessCubeNoCalculate(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs)
			'------------------------------------------------------------------------------------------------------------
			'Reference Code: 	XFR_HandleProcessCubeNoCalculate 
			'
			'Description:		Run a DataMgmt Sequence after the workflow process cube task is run.
			'					Note: the DataMgmt sequence name is assigned to a Workflow Profile CalcDef filter field
			'					so this event does not have to be modified, the user can simply edit the CalcDef grid
			'					for a workflow profile and this business rule will execucte the specified sequence. 
			'					*******Note******** This is designed to prevent a DM job from triggering more than 
			'					once for range scenarios that span multiple years.
			'
			'Usage:				Used to kick off a DM job specified in a No Calculate calculation definition and pass the entity filter
			'					specified on the calculation defintion to the entity filter in the data mgmt job.
			'------------------------------------------------------------------------------------------------------------
			Try
				'Get the DataUnitInfo from the Event arguments so that we can get the name of the DataManagement sequence to process.
				Dim calcInfo As DataUnitInfo = DirectCast(args.Inputs(2), DataUnitInfo)
				Dim WfUnitPK As WorkflowUnitPk = DirectCast(args.Inputs(0), WorkflowUnitPk)
				
				If Not Brapi.Workflow.Metadata.GetProfile(si,WfUnitPK.ProfileKey).IsInputChild
					If Not calcInfo Is Nothing Then	
						'Make sure that a Sequence name is assigned to the filter value of the Calc Definition of the executing Workflow Profile
						If calcInfo.FilterValue <> String.Empty Then
							'set the passEntityCalcDef variable to true if there is a need to pass the calculation definition entity value to the DM job
							Dim passEntityCalcDef As Boolean = False
							'dictionary of DM job params
							Dim dmParams As New Dictionary(Of String, String)
							'if we want to pass the entity from the calc def to the DM job, specify a parameter on the DM job called ParamEntity
							If passEntityCalcDef Then
								'pass the entity from the calc def to the ParamEntity parameter on the DM job. Swap ParamEntity with your custom parameter name
								dmParams.Add("ParamEntity", calcInfo.DataUnitNames.EntityName)
							End If
							Dim varScenarioID As String = calcInfo.DataUnitIds.ScenarioId
							Dim wfTracking As WorkflowTrackingFrequency = BRApi.Finance.Scenario.GetWorkflowTrackingFrequency(si, varScenarioID)
							'if the workflow tracking frequency is range, ensure we are only executing a DM sequence for the first year in the range
							If wfTracking = WorkflowTrackingFrequency.Range Then
								Dim processedYear As Integer = BRApi.Finance.Time.GetYearFromId(si, calcInfo.DataUnitIds.TimeId)
								Dim wfStartTime As Integer = BRApi.Finance.Scenario.GetWorkflowStartTime(si, varScenarioID)
								Dim firstWFStartYear As Integer = BRApi.Finance.Time.GetYearFromId(si, wfStartTime)
								If processedYear = firstWFStartYear Then
									'Now, execute the DataMgmt Sequence that was specified in the FilterValue (In a background thread)
									BRApi.Utilities.StartDataMgmtSequence(si, calcInfo.FilterValue, dmParams)					
								End If
							'non range scenarios
							Else
								'Now, start the DataMgmt Sequence that was specified in the FilterValue (In a background thread)
								BRApi.Utilities.StartDataMgmtSequence(si, calcInfo.FilterValue, dmParams)
							End If
						End If
						
					End If 
				End If
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Sub
#End Region

 

 

 

  

View solution in original post

4 REPLIES 4

aformenti
Contributor II

HI @Richard_Mayo,

This is expected behavior as the base Workflow steps will inherit the Base Input Calculations definitions if they are left blank. So, the No Calculate will run as soon as the base workflow steps have the Process step enabled. 

Do you need the Process step in the base Workflow Profiles (3) ? If you do need them, could you maybe try to create a No Calculate step for the base workflows with the Filter blank? Not ideal but it could make the trick?

FredLucas
Contributor II

Hi @Richard_Mayo,

You'll hopefully find the answer to your question on the above options given by @aformenti.

However, if that's not the case, or you need something a little bit more dynamic / custom, here is another option you could explore: 

As you probably know OS does not trigger sequences on No Calculate by default, that sequence is triggered via a custom function defined as part of the DataQualityEventHandler.

Having said that, you could update this custom function (that triggers the sequences defined on the No Calculate) to only trigger it if a certain criteria is met. The criteria could be for example: if the Workflow step is a base step or of a certain type, if there's a specific Text property defined, if it follows a specific naming convention, if the name matches the one passed on as a parameter, etc, etc.

aformenti
Contributor II

That's a good idea @Fred

See below a screenshot of an slide explaining what Fred means:

aformenti_0-1718266629170.png

The code would be something like this:

#Region "ProcessCube.NoCalculate Helpers"
		Private Sub OSB_HandleProcessCubeNoCalculate(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs)
			'------------------------------------------------------------------------------------------------------------
			'Reference Code: 	XFR_HandleProcessCubeNoCalculate 
			'
			'Description:		Run a DataMgmt Sequence after the workflow process cube task is run.
			'					Note: the DataMgmt sequence name is assigned to a Workflow Profile CalcDef filter field
			'					so this event does not have to be modified, the user can simply edit the CalcDef grid
			'					for a workflow profile and this business rule will execucte the specified sequence. 
			'					*******Note******** This is designed to prevent a DM job from triggering more than 
			'					once for range scenarios that span multiple years.
			'
			'Usage:				Used to kick off a DM job specified in a No Calculate calculation definition and pass the entity filter
			'					specified on the calculation defintion to the entity filter in the data mgmt job.
			'------------------------------------------------------------------------------------------------------------
			Try
				'Get the DataUnitInfo from the Event arguments so that we can get the name of the DataManagement sequence to process.
				Dim calcInfo As DataUnitInfo = DirectCast(args.Inputs(2), DataUnitInfo)
				Dim WfUnitPK As WorkflowUnitPk = DirectCast(args.Inputs(0), WorkflowUnitPk)
				
				If Not Brapi.Workflow.Metadata.GetProfile(si,WfUnitPK.ProfileKey).IsInputChild
					If Not calcInfo Is Nothing Then	
						'Make sure that a Sequence name is assigned to the filter value of the Calc Definition of the executing Workflow Profile
						If calcInfo.FilterValue <> String.Empty Then
							'set the passEntityCalcDef variable to true if there is a need to pass the calculation definition entity value to the DM job
							Dim passEntityCalcDef As Boolean = False
							'dictionary of DM job params
							Dim dmParams As New Dictionary(Of String, String)
							'if we want to pass the entity from the calc def to the DM job, specify a parameter on the DM job called ParamEntity
							If passEntityCalcDef Then
								'pass the entity from the calc def to the ParamEntity parameter on the DM job. Swap ParamEntity with your custom parameter name
								dmParams.Add("ParamEntity", calcInfo.DataUnitNames.EntityName)
							End If
							Dim varScenarioID As String = calcInfo.DataUnitIds.ScenarioId
							Dim wfTracking As WorkflowTrackingFrequency = BRApi.Finance.Scenario.GetWorkflowTrackingFrequency(si, varScenarioID)
							'if the workflow tracking frequency is range, ensure we are only executing a DM sequence for the first year in the range
							If wfTracking = WorkflowTrackingFrequency.Range Then
								Dim processedYear As Integer = BRApi.Finance.Time.GetYearFromId(si, calcInfo.DataUnitIds.TimeId)
								Dim wfStartTime As Integer = BRApi.Finance.Scenario.GetWorkflowStartTime(si, varScenarioID)
								Dim firstWFStartYear As Integer = BRApi.Finance.Time.GetYearFromId(si, wfStartTime)
								If processedYear = firstWFStartYear Then
									'Now, execute the DataMgmt Sequence that was specified in the FilterValue (In a background thread)
									BRApi.Utilities.StartDataMgmtSequence(si, calcInfo.FilterValue, dmParams)					
								End If
							'non range scenarios
							Else
								'Now, start the DataMgmt Sequence that was specified in the FilterValue (In a background thread)
								BRApi.Utilities.StartDataMgmtSequence(si, calcInfo.FilterValue, dmParams)
							End If
						End If
						
					End If 
				End If
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Sub
#End Region

 

 

 

  

Richard_Mayo
New Contributor III

Thankyou both @aformenti and @FredLucas for taking the time to answer my question. I have made it work now based on your advice. Many thanks!

Richard