Skip to main content
January 22, 2026
Solved

Help with event handlers

  • January 22, 2026
  • 2 replies
  • 4 views

Hi

I am trying to understand the event handlers to see if we can leverage them to improve user experience and put some controls around recurring issues.  

But the documentation is not helping. I think I figured the events in general and when they execute but can someone please explain the purpose of "Is Before Event", "Can Cancel", and "args.Inputs(x)"

Thank you in advance,

PM

 

Best answer by MarcusH

The event handlers are called before and after most events allowing you to check things at different steps in the process. As an example, for the TransformationEventHandler if the operation is ProcessTransformRules, IsBeforeEvent = True means that the Transformation Rules have not yet been applied so if you are wanting to check any target values, it won't work because there are none. But you can check the Transformation Rules themselves at this point (you might have a process where a Transformation Rule is flagged for deletion by changing the description to DELETE, and you then execute a SQL statement to delete these maps). There is no point doing this when IsBeforeEvent = False because the maps have already been processed.

CanCancel is a property that is monitored during the Transformation process. If it is set to True the process stops. You use it something like this:

If foundRecordToExport = False Then
    args.Cancel = True
End If

But there are only a few operations where the Cancel property is monitored.

args.Inputs contains information that is relevant to the current operation. For the TransformationEventHandler args.Inputs(0) contains the data being processed at that step. For the ProcessTransformationRules step it contains the Stage data and it is accessed like this:

Dim objTransformer As Transformer = DirectCast(args.Inputs(0), Transformer)

' The stage data is in the DataCache object. Check there is data
If objTransformer.DataCache.Pages.Count > 0 Then
	' Target UD2
	Dim tUD2ColIndex As Integer = (objTransformer.TransformerDimensions(StageConstants.MasterDimensionNames.UD2).DataTableColumnIndex) + StageConstants.TransformationColumnIncrements.Target
	' Source Account
	Dim AccountColIndex As Integer = objTransformer.TransformerDimensions(StageConstants.MasterDimensionNames.Account).DataTableColumnIndex
	' This is the exchange rate itself
	Dim AmountColIndex As Integer = objTransformer.TransformerDimensions(StageConstants.MasterDimensionNames.Amount).DataTableColumnIndex

	' Read through all the pages in the data cache
	objTransformer.DataCache.MoveFirstPage(si)
	For intPageNo As Integer = 0 To objTransformer.DataCache.Pages.Count - 1
		objTransformer.DataCache.ActivatePage(si, intPageNo) 
		' read through each row on the page
		For Each row As DataRow In objTransformer.DataCache.CurrentPage.PageDataTable.Rows
			Try
				Dim targetUD2 As String = row(tUD2ColIndex)
				....
			Catch ex As Exception
				Brapi.ErrorLog.LogMessage(si, ex.Message)
			End Try
		Next     ' Each row As DataRow In objTransformer.DataCache.CurrentPage.PageDataTable.Rows							
	Next         ' For intPageNo As Integer = 0 To objTransformer.DataCache.Pages.Count - 1
End If

For the FinalizeValidateTransform operation args.Inputs(0) holds different data and is accessed in another way:

'Get the current workflow process instance info object
Dim processInfo As ValidationTransformationProcessInfo = DirectCast(args.Inputs(0), ValidationTransformationProcessInfo)

'When you fail, just add the message to the process Info
Dim status As String = "Fail" 											'(Pass / Fail)
Dim ruleMessage As String = "Incorrect source entity [" & IncorrectEntities & "]"  	'(Rule information, explain what is wrong)
Dim correctiveAction As String = "Check the source file is correct."							'(Information to fix the problem)

'Add this item to the list
processInfo.FailedEventRules.Add(New ThreeStrings(status, ruleMessage, correctiveAction))
' Set the status to Error
processinfo.Status = WorkflowStatusTypes.HasError 

Other eventhandlers of course have different data in args.Inputs. For example the DataQualityEventHandler:

#Region "Operation: ProcessCube"
Dim wfUnitPK As WorkflowUnitPk = DirectCast(args.inputs(0), WorkflowUnitPk)
Dim tskActivity As TaskActivityItem = DirectCast(args.inputs(1), TaskActivityItem)
Dim calcInfo As DataUnitInfo = DirectCast(args.Inputs(2), DataUnitInfo)
#End Region
#Region "Operation: ICTransStatus"
Dim TransactionStatus As ICMatchStatusInfo = DirectCast(args.inputs(0), ICMatchStatusInfo)
#End Region

I have not found any documentation on the args.Inputs structure. When I need to add a Business Rule at a particular operation, I add a debug where it prints out the values and datatypes for each of elements in args.Inputs array.

2 replies

MarcusHAnswer
January 23, 2026

The event handlers are called before and after most events allowing you to check things at different steps in the process. As an example, for the TransformationEventHandler if the operation is ProcessTransformRules, IsBeforeEvent = True means that the Transformation Rules have not yet been applied so if you are wanting to check any target values, it won't work because there are none. But you can check the Transformation Rules themselves at this point (you might have a process where a Transformation Rule is flagged for deletion by changing the description to DELETE, and you then execute a SQL statement to delete these maps). There is no point doing this when IsBeforeEvent = False because the maps have already been processed.

CanCancel is a property that is monitored during the Transformation process. If it is set to True the process stops. You use it something like this:

If foundRecordToExport = False Then
    args.Cancel = True
End If

But there are only a few operations where the Cancel property is monitored.

args.Inputs contains information that is relevant to the current operation. For the TransformationEventHandler args.Inputs(0) contains the data being processed at that step. For the ProcessTransformationRules step it contains the Stage data and it is accessed like this:

Dim objTransformer As Transformer = DirectCast(args.Inputs(0), Transformer)

' The stage data is in the DataCache object. Check there is data
If objTransformer.DataCache.Pages.Count > 0 Then
	' Target UD2
	Dim tUD2ColIndex As Integer = (objTransformer.TransformerDimensions(StageConstants.MasterDimensionNames.UD2).DataTableColumnIndex) + StageConstants.TransformationColumnIncrements.Target
	' Source Account
	Dim AccountColIndex As Integer = objTransformer.TransformerDimensions(StageConstants.MasterDimensionNames.Account).DataTableColumnIndex
	' This is the exchange rate itself
	Dim AmountColIndex As Integer = objTransformer.TransformerDimensions(StageConstants.MasterDimensionNames.Amount).DataTableColumnIndex

	' Read through all the pages in the data cache
	objTransformer.DataCache.MoveFirstPage(si)
	For intPageNo As Integer = 0 To objTransformer.DataCache.Pages.Count - 1
		objTransformer.DataCache.ActivatePage(si, intPageNo) 
		' read through each row on the page
		For Each row As DataRow In objTransformer.DataCache.CurrentPage.PageDataTable.Rows
			Try
				Dim targetUD2 As String = row(tUD2ColIndex)
				....
			Catch ex As Exception
				Brapi.ErrorLog.LogMessage(si, ex.Message)
			End Try
		Next     ' Each row As DataRow In objTransformer.DataCache.CurrentPage.PageDataTable.Rows							
	Next         ' For intPageNo As Integer = 0 To objTransformer.DataCache.Pages.Count - 1
End If

For the FinalizeValidateTransform operation args.Inputs(0) holds different data and is accessed in another way:

'Get the current workflow process instance info object
Dim processInfo As ValidationTransformationProcessInfo = DirectCast(args.Inputs(0), ValidationTransformationProcessInfo)

'When you fail, just add the message to the process Info
Dim status As String = "Fail" 											'(Pass / Fail)
Dim ruleMessage As String = "Incorrect source entity [" & IncorrectEntities & "]"  	'(Rule information, explain what is wrong)
Dim correctiveAction As String = "Check the source file is correct."							'(Information to fix the problem)

'Add this item to the list
processInfo.FailedEventRules.Add(New ThreeStrings(status, ruleMessage, correctiveAction))
' Set the status to Error
processinfo.Status = WorkflowStatusTypes.HasError 

Other eventhandlers of course have different data in args.Inputs. For example the DataQualityEventHandler:

#Region "Operation: ProcessCube"
Dim wfUnitPK As WorkflowUnitPk = DirectCast(args.inputs(0), WorkflowUnitPk)
Dim tskActivity As TaskActivityItem = DirectCast(args.inputs(1), TaskActivityItem)
Dim calcInfo As DataUnitInfo = DirectCast(args.Inputs(2), DataUnitInfo)
#End Region
#Region "Operation: ICTransStatus"
Dim TransactionStatus As ICMatchStatusInfo = DirectCast(args.inputs(0), ICMatchStatusInfo)
#End Region

I have not found any documentation on the args.Inputs structure. When I need to add a Business Rule at a particular operation, I add a debug where it prints out the values and datatypes for each of elements in args.Inputs array.

January 26, 2026

Regarding "documentation on the args.Inputs structure": Please note that they can be found here in the "API Overview Guide" documentation - Event Firing Sequences

MikkiAuthor
January 23, 2026

Thank you very much for taking time and explaining in detail. This is incredibly helpful.