Skip to main content
December 10, 2024
Solved

Calculation Definitions Filter -Data Quality Event Handler

  • December 10, 2024
  • 3 replies
  • 1 view

Hello, 

I setup a filter on a workflow profile calculation to run a data management job as long as the no calculate is the selected option. 

We have a Data Quality Event Handler Business rule to run this; however when I click on process cube, it's running the job twice at the same time. 



This is the example of what it's doing when I say it's running twice:



 

 

Here it the code from the event handler:

Namespace OneStream.BusinessRule.DataQualityEventHandler.DataQualityEventHandler
	Public Class MainClass
		'------------------------------------------------------------------------------------------------------------
		'Reference Code: 	DataQualityEventHandler 
		'
		'Description:		Event handler method that provides an opertunity to supplement a normal data quality
		'					action with your own custom functionality. 
		'					(Example: email after ProcessCube or publish report to sharepoint after failed Confirmation).
		'
		'Usage:				Executes when a Data Quality action is run and fires this business rule.  If you have written
		'					code in that handles the specified event operation the code will be executed.
		'				
		'Created By:		Tom Shea
		'Date Created:		1-30-2013
		'------------------------------------------------------------------------------------------------------------		
		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs) As Object
			Try
				'Define a switch to control event processing, since many of these are reference examples we do not want them to run all the time
				Dim processEvents As Boolean = False

				'Set the default return values
				Dim returnValue As Object = args.DefaultReturnValue
				args.UseReturnValueFromBusinessRule = False
				args.Cancel = False

				'Evaluate the operation type in order to determine which subroutine to process
				Select Case args.OperationName
					Case Is = BREventOperationType.DataQuality.ProcessCube.NoCalculate
						'Execute a Data Management job after process cube runs
						Me.XFR_HandleProcessCubeNoCalculate(si, globals, api, args)
						
					'Case Is = BREventOperationType.DataQuality.Certify.FinalizeSetCertifyState
						'Send an email after a workflow profile executes its certification
						'Me.XFR_HandleFinalizeSetCertifyState(si, globals, api, args)						
						
				End Select
				
				Return returnValue
				
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Function
		
#Region "ProcessCube.NoCalculate Helpers"
		
		Private Sub XFR_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.
			'
			'Usage:				Used to supplement the standard "ProcessCube" functionality associated with a 
			'					workflow profile by allowing a DataManagement sequence to be executed for the workflow profile
			'					as well.
			'
			'Created By:		Tom Shea
			'Date Created:		1-30-2013
			'------------------------------------------------------------------------------------------------------------
			Try
				'Get the DataUnitInfo from the Event arguaments so that we can get the name of the DataManagement sequence to process.
				Dim calcInfo As DataUnitInfo = DirectCast(args.Inputs(2), DataUnitInfo)
				If Not calcInfo Is Nothing Then					
					'Make sure that a Sequence name as assigned to the filter value of the Calc Definition of the executing Workflow Profile 
					If calcInfo.FilterValue <> String.Empty Then						
						'Now, execute the DataMgmt Sequence that was specified in the FilterValue (In a background thread)
						BRApi.Utilities.StartDataMgmtSequence(si, calcInfo.FilterValue, Nothing)					
					End If
				End If

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

#End Region


	End Class
End Namespace

This is the first time I am setting up an event like this and I am not very good at business rules, so any suggestions or help would be much appreciated! Thank you

Best answer by Big_Rick_CPM

I would just check the WF start time and just run it for that year only. But there could be other ways to do this depending on your setup.

Imports System
Imports System.Data
Imports System.Data.Common
Imports System.IO
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Net.Mail
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports OneStream.Shared.Common
Imports OneStream.Shared.Wcf
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Database
Imports OneStream.Stage.Engine
Imports OneStream.Stage.Database
Imports OneStream.Finance.Engine
Imports OneStream.Finance.Database

Namespace OneStream.BusinessRule.DataQualityEventHandler.DataQualityEventHandler
	Public Class MainClass
		'------------------------------------------------------------------------------------------------------------
		'Reference Code: 	DataQualityEventHandler 
		'
		'Description:		Event handler method that provides an opertunity to supplement a normal data quality
		'					action with your own custom functionality. 
		'					(Example: email after ProcessCube or publish report to sharepoint after failed Confirmation).
		'
		'Usage:				Executes when a Data Quality action is run and fires this business rule.  If you have written
		'					code in that handles the specified event operation the code will be executed.
		'				
		'Created By:		Tom Shea
		'Date Created:		1-30-2013
		'------------------------------------------------------------------------------------------------------------		
		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs) As Object
			Try
				'Define a switch to control event processing, since many of these are reference examples we do not want them to run all the time
				Dim processEvents As Boolean = False

				'Set the default return values
				Dim returnValue As Object = args.DefaultReturnValue
				args.UseReturnValueFromBusinessRule = False
				args.Cancel = False

				'Evaluate the operation type in order to determine which subroutine to process
				Select Case args.OperationName
					Case Is = BREventOperationType.DataQuality.ProcessCube.NoCalculate
						'Execute a Data Management job after process cube runs
						Me.XFR_HandleProcessCubeNoCalculate(si, globals, api, args)
						
					'Case Is = BREventOperationType.DataQuality.Certify.FinalizeSetCertifyState
						'Send an email after a workflow profile executes its certification
						'Me.XFR_HandleFinalizeSetCertifyState(si, globals, api, args)						
						
				End Select
				
				Return returnValue
				
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Function
		
#Region "ProcessCube.NoCalculate Helpers"
		
		Private Sub XFR_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.
			'
			'Usage:				Used to supplement the standard "ProcessCube" functionality associated with a 
			'					workflow profile by allowing a DataManagement sequence to be executed for the workflow profile
			'					as well.
			'
			'Created By:		Tom Shea
			'Date Created:		1-30-2013
			'------------------------------------------------------------------------------------------------------------
			Try
				'Get the DataUnitInfo from the Event arguaments so that we can get the name of the DataManagement sequence to process.
				Dim calcInfo As DataUnitInfo = DirectCast(args.Inputs(2), DataUnitInfo)
				If Not calcInfo Is Nothing Then					
					'Make sure that a Sequence name as assigned to the filter value of the Calc Definition of the executing Workflow Profile 
					If calcInfo.FilterValue <> String.Empty Then
'**************************************************************
' NEW CHECK TO ONLY RUN ON THE START YEAR OF WF RANGE TIME
						If timedimhelper.GetYearFromId(calcInfo.DataUnitIds.TimeId).Equals(timedimhelper.GetYearFromId(brapi.Finance.Scenario.GetWorkflowStartTime(si,calcInfo.DataUnitIds.ScenarioId)))
'**************************************************************
						'	Now, execute the DataMgmt Sequence that was specified in the FilterValue (In a background thread)
							Dim params As New Dictionary(Of String, String)
							BRApi.Utilities.StartDataMgmtSequence(si, calcInfo.FilterValue, params)		
						End If
					End If
				End If

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

#End Region


	End Class
End Namespace

 

3 replies

December 11, 2024

How many entities are assigned to your workflow profile? This setting means it will run the DM Sequence for each entity.



 

aorangeAuthor
December 11, 2024

Thank you for the reply.  There are 3 entities assigned to this one.  I also tried selecting the parent entity under the entity field and leaving the parent blank, as well as selecting the parent.  I am not sure which combo will give me the results I am looking for.  Both of the tasks that ran, ran for the same entities if I look at the details of them.

aorangeAuthor
December 11, 2024

Actually I figured out this has something to do with the business rule.  In the rule it's saying that it's going to run the data management job after the process cube it run.  I need to figure out how to tell it to only run the data management job and not any other process cube jobs. 

December 11, 2024

What do you mean by other process cube jobs?

aorangeAuthor
December 11, 2024

It's running the other calculation definitions set on the workflow profile and then the Data Management job, but for some reason it's running the data management job twice still. I think I'm ok with it running the process cube (which is a calculate job) and then the data management job. But I'm just coming up empty on why it's pushing it twice.

If you look at the code I added above the helper function says:

"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."

December 11, 2024

In my experience with this, the process step will trigger by workflow time so having multiple years/data units within the workflow unit can cause this. E.g. do you have a WF range that spans 2 years? If so, it is running the process step for the first year then the second year. 

Make sure to keep that in mind when building the DM sequence and rules (e.g. you don't want or need to run the same process twice on the same period so make sure you add logic or a process to account for how this runs).

aorangeAuthor
December 11, 2024

Thank you for the reply!  I think maybe this is what is happening, we have a rolling forecast that spans over two years, but it looks like it's running the job both times for the same time periods. We have a XFBR rule that is used for the time on the DM job.

Are you able to offer a suggestion on how I limit it to only calculate once for the entire time period? I am not really good with business rules. 

 

December 11, 2024

I would just check the WF start time and just run it for that year only. But there could be other ways to do this depending on your setup.

Imports System
Imports System.Data
Imports System.Data.Common
Imports System.IO
Imports System.Collections.Generic
Imports System.Globalization
Imports System.Net.Mail
Imports Microsoft.VisualBasic
Imports System.Windows.Forms
Imports OneStream.Shared.Common
Imports OneStream.Shared.Wcf
Imports OneStream.Shared.Engine
Imports OneStream.Shared.Database
Imports OneStream.Stage.Engine
Imports OneStream.Stage.Database
Imports OneStream.Finance.Engine
Imports OneStream.Finance.Database

Namespace OneStream.BusinessRule.DataQualityEventHandler.DataQualityEventHandler
	Public Class MainClass
		'------------------------------------------------------------------------------------------------------------
		'Reference Code: 	DataQualityEventHandler 
		'
		'Description:		Event handler method that provides an opertunity to supplement a normal data quality
		'					action with your own custom functionality. 
		'					(Example: email after ProcessCube or publish report to sharepoint after failed Confirmation).
		'
		'Usage:				Executes when a Data Quality action is run and fires this business rule.  If you have written
		'					code in that handles the specified event operation the code will be executed.
		'				
		'Created By:		Tom Shea
		'Date Created:		1-30-2013
		'------------------------------------------------------------------------------------------------------------		
		Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs) As Object
			Try
				'Define a switch to control event processing, since many of these are reference examples we do not want them to run all the time
				Dim processEvents As Boolean = False

				'Set the default return values
				Dim returnValue As Object = args.DefaultReturnValue
				args.UseReturnValueFromBusinessRule = False
				args.Cancel = False

				'Evaluate the operation type in order to determine which subroutine to process
				Select Case args.OperationName
					Case Is = BREventOperationType.DataQuality.ProcessCube.NoCalculate
						'Execute a Data Management job after process cube runs
						Me.XFR_HandleProcessCubeNoCalculate(si, globals, api, args)
						
					'Case Is = BREventOperationType.DataQuality.Certify.FinalizeSetCertifyState
						'Send an email after a workflow profile executes its certification
						'Me.XFR_HandleFinalizeSetCertifyState(si, globals, api, args)						
						
				End Select
				
				Return returnValue
				
			Catch ex As Exception
				Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
			End Try
		End Function
		
#Region "ProcessCube.NoCalculate Helpers"
		
		Private Sub XFR_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.
			'
			'Usage:				Used to supplement the standard "ProcessCube" functionality associated with a 
			'					workflow profile by allowing a DataManagement sequence to be executed for the workflow profile
			'					as well.
			'
			'Created By:		Tom Shea
			'Date Created:		1-30-2013
			'------------------------------------------------------------------------------------------------------------
			Try
				'Get the DataUnitInfo from the Event arguaments so that we can get the name of the DataManagement sequence to process.
				Dim calcInfo As DataUnitInfo = DirectCast(args.Inputs(2), DataUnitInfo)
				If Not calcInfo Is Nothing Then					
					'Make sure that a Sequence name as assigned to the filter value of the Calc Definition of the executing Workflow Profile 
					If calcInfo.FilterValue <> String.Empty Then
'**************************************************************
' NEW CHECK TO ONLY RUN ON THE START YEAR OF WF RANGE TIME
						If timedimhelper.GetYearFromId(calcInfo.DataUnitIds.TimeId).Equals(timedimhelper.GetYearFromId(brapi.Finance.Scenario.GetWorkflowStartTime(si,calcInfo.DataUnitIds.ScenarioId)))
'**************************************************************
						'	Now, execute the DataMgmt Sequence that was specified in the FilterValue (In a background thread)
							Dim params As New Dictionary(Of String, String)
							BRApi.Utilities.StartDataMgmtSequence(si, calcInfo.FilterValue, params)		
						End If
					End If
				End If

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

#End Region


	End Class
End Namespace