Forum Discussion
mireles
1 year agoNew Contributor III
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)
6 Replies
- SimonHesfordContributor II
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.
- mirelesNew Contributor III
Thank you SimonHesford!
- MarcusHValued 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)- MarcusHValued Contributor
I haven't found much documentation on the args structure. Whenever I need to use them, I get the info using intellisense and debugs. I then add the info to the top of the BR like this:
#Region "DataQuality args, steps and operations list" #Region "Steps" ' DataQuality steps: ' BREventOperationType.DataQuality.Certify ' BREventOperationType.DataQuality.Confirm ' BREventOperationType.DataQuality.ICTransStatus ' BREventOperationType.DataQuality.PrepareICMatch ' BREventOperationType.DataQuality.ProcessCube #End Region #Region "Operation: Certify" ' DataQuality Certify operations: ' BREventOperationType.DataQuality.Certify.EndSetCertifyState ' BREventOperationType.DataQuality.Certify.EndSetQuestionairreState ' BREventOperationType.DataQuality.Certify.FinalizeSaveQuestionResponse ' BREventOperationType.DataQuality.Certify.FinalizeSetCertifyState ' BREventOperationType.DataQuality.Certify.FinalizeSetQuestionairreState ' BREventOperationType.DataQuality.Certify.SaveCertifyState ' BREventOperationType.DataQuality.Certify.SaveQuestionairreState ' BREventOperationType.DataQuality.Certify.SaveQuestionResponse ' BREventOperationType.DataQuality.Certify.StartSetCertifyState ' BREventOperationType.DataQuality.Certify.StartSetQuestionairreState #End Region #Region "Operation: Confirm" ' DataQuality Confirm operations: ' BREventOperationType.DataQuality.Confirm.EndConfirm ' BREventOperationType.DataQuality.Confirm.FinalizeConfirm ' BREventOperationType.DataQuality.Confirm.StartConfirm #End Region #Region "Operation: ICTransStatus" ' DataQuality ICTransStatus operations: ' BREventOperationType.DataQuality.ICTransStatus.AddICTransactionStatus ' BREventOperationType.DataQuality.ICTransStatus.FinalizeAddICTransactionStatus #End Region #Region "Operation: PrepareICMatch" ' DataQuality PrepareICMatch operations: ' BREventOperationType.DataQuality.PrepareICMatch.EndICMatch ' BREventOperationType.DataQuality.PrepareICMatch.PrepareICMatchData ' BREventOperationType.DataQuality.PrepareICMatch.StartICMatch #End Region #Region "Operation: ProcessCube" ' ProcessCube operations: ' BREventOperationType.DataQuality.ProcessCube.Calculate ' BREventOperationType.DataQuality.ProcessCube.Consolidate ' BREventOperationType.DataQuality.ProcessCube.EndProcessCube ' BREventOperationType.DataQuality.ProcessCube.NoCalculate ' BREventOperationType.DataQuality.ProcessCube.StartProcessCube ' BREventOperationType.DataQuality.ProcessCube.Translate #End Region #Region "args inputs" #Region "Operation: Certify" ' Dim wfUnitClust As WorkflowUnitPk = DirectCast(args.Inputs(1), WorkflowUnitPk) ' Dim certifyInstance As CertifyInstanceInfo = DirectCast(args.Inputs(2), CertifyInstanceInfo) ' Dim certifyInstance As CertifySignOffInstanceInfo = DirectCast(args.Inputs(2), CertifySignOffInstanceInfo) #End Region #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 #End Region #End RegionIf I ever have to use the DataQualityEventHandler for the Confirm or PrepareICMatch steps, I will investigate and update the header.
Related Content
- 1 year ago
- 2 years ago