Forum Discussion

mireles's avatar
mireles
New Contributor II
27 days ago
Solved

How do I get workflow info on a DataQualityEventHandler rule?

I'm making a simple event handler rule that sends an email when a workflow is processed. I would like the email to include the datetime when it was processed, the user who did it, the workflow, workflow profile and entity. However I've only been able to include the date and time. My code is structured like this:

  • Main calls the sub XFR_HandleEndProcessCube()
Public Function Main(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs) As Object
	Try
		Dim returnValue As Object = args.DefaultReturnValue
		args.UseReturnValueFromBusinessRule = False
		args.Cancel = False

		Select Case args.OperationName
		Case Is = BREventOperationType.DataQuality.ProcessCube.EndProcessCube
			Me.XFR_HandleEndProcessCube(si, globals, api, args)
		End Select

		Return returnValue
	Catch ex As Exception
		Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
	End Try
End Function
  • XFR_HandleEndProcessCube() sub sends the email, using the helper function ComposeMessageBody()
Private Sub XFR_HandleEndProcessCube(ByVal si As SessionInfo, ByVal globals As BRGlobals, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs)
	Try
		' Send an email when EndProcessCube happens
		' Set email parameters
		Dim emailConnectionName As String = "..."
		Dim toEmailAddresses As New List(Of String) From {"..."} 'TODO: Make dynamic!
		Dim subject As String = "Test Email from OneStream"
		Dim body As String = ComposeMessageBody(si, api, args)
		Dim isBodyHtml As Boolean = True
		
		BRApi.Utilities.SendMail(si, emailConnectionName, toEmailAddresses, subject, body, isBodyHtml, Nothing)
	Catch ex As Exception
		Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
	End Try
End Sub
  • The code for ComposeMessageBody():
Private Function ComposeMessageBody(ByVal si As SessionInfo, ByVal api As Object, ByVal args As DataQualityEventHandlerArgs) As String
	Try
			Dim messageBody As New Text.StringBuilder
			
		messageBody.AppendLine("<style>th,td{border: 1px solid; padding: 5px;}</style>")
		messageBody.AppendLine("<h2>The following workflow has been processed successfully:</h2>")
		messageBody.AppendLine("<table>")
		messageBody.AppendLine("<tr><th>Attribute</th><th>Description</th></tr>")
		messageBody.AppendLine("<tr><td>User</td><td>" & si.UserName & "</td></tr>")
		messageBody.AppendLine("<tr><td>Time Completed</td><td>" & DateTime.Now.ToLocalTime.ToString() & "</td></tr>")
		'messageBody.AppendLine("<tr><td>Workflow</td><td>" & api.Workflow.CurrentWorkflowProfile.Name & "</td></tr>")
		'messageBody.AppendLine("<tr><td>Cube</td><td>" & api.Pov.Cube.Name & "</td></tr>")
		messageBody.AppendLine("</table>")
		
		Return messageBody.ToString()
	Catch ex As Exception
		Throw ErrorHandler.LogWrite(si, New XFException(si, ex))
	End Try
End Function

As you can see from the lines commented above I've tried using api.Workflow and api.Pov. However, using either results in a "object variable or with block variable not set" error.

What alternatives do I have for including this data in the business rule?

  • As SimonHesford says you can get that information from the args object. The structure of args varies according to the step that is being processed. For ProcessCube you access it like this:

    ' 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)

     

  • MarcusH's avatar
    MarcusH
    Valued Contributor

    As SimonHesford says you can get that information from the args object. The structure of args varies according to the step that is being processed. For ProcessCube you access it like this:

    ' 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)

     

  • Hi, 

    You need to make use of the DataQualityEventHandlerArgs.

    args.inputs(1) will return a reference to the WorkflowUnitPk. You can use the properties on this object to retrieve the workflow profile info which should provide most of the information you are looking to surface.