Execute Workflows from Compliance Rules
Example of executing workflow as a result of the compliance rule (CoRu) trigger
Table of Contents
Overview
You can execute workflows as a result of the compliance rule (CoRu) trigger. This is a preferred way of executing custom business logic from the CoRu, because it allows defining custom business processes in the Workflow Studio without any coding. As an input, the workflow takes a list of affected objects from the CoRu that can be used to retrieve additional information and process these objects in a sequence.
Workflow Creation
To be executed from the CoRu, a workflow should meet the following criteria:
Integration Context: Compliance Rules
Input Arguments
| Name | Direction | Argument Type | Default Value |
|---|---|---|---|
ObjectContexts |
In | ComplianceRuleObjectActionContext[] |
Where ComplianceRuleObjectActionContext[] is a set of ComplianceRuleObjectActionContext objects, it is created automatically.
The workflow always takes a list of objects, regardless of the number of objects that are affected by actions. The idea is to iterate through the list of objects and process each record in a sequence. You can use ComplianceRuleObjectActionContext to retrieve additional data for the corresponding object.
ComplianceRuleObjectActionContext contains the following properties:
| Property | Data Type | Description |
|---|---|---|
CI |
Guid | Identifier of the configuration item (TypeID). |
ID |
Guid | Identifier of the corresponding object (Expression-ObjectID). |
Created |
DateTime | Time when the event has been fired. |
User |
Guid | Identifier of the user who triggers the action. |
ComplianceRuleObjectActionContext contains the following methods:
-
GetBeforeData: relevant only for Workflows triggered by a Compliance Rule with Condition Type "Change an Object". Use this method to obtain the previous value of the changed object property.
Attributes:
-
attrName: the name of the changed property parameter defined in Compliance Rule Workflow Action. -
defaultValue: optional. If the "before value" is not available, the function returns the specified "default" value
Example:
item.GetBeforeData(of String)("email", "john.snow@blackcastle.gov")
To create a workflow for a compliance rule, perform the following steps:
- Run the Workflow Studio and create a
Newworkflow from theCompliance Rules - WF Templatetemplate:
- Define the
Name,Icon, andCategoryfor the workflow, set theIntegration ContexttoCompliance Rules, and then clickSave:
- As a result, the system creates a workflow with predefined input arguments:
- The
ForEachactivity from theRepositorytoolbox is connected to theStartactivity.
- In the Properties toolbox of the
ForEachactivity, theTypeArgumentis set toMatrix42.ServiceRepository.Contracts.DataContracts.ComplianceRuleObjectActionContext
If the TypeArgument is not set, choose Browse for Types... and in the dialog search for ComplianceRuleObjectActionContext, select it and click OK to confirm the selection.
- In the
Propertiestoolbox, selectValues, and then typeObjectContexts:
You can do the same by double-clicking the ForEach activity and using the extended activity designer.

- Drag the
Flowchartactivity into the Body of theForEachactivity.
The Bodyof the ForEach activity is executed for every affected object that is passed as an input into the workflow.
The name of the current object in context is item.
- Double-click the
Flowchartactivity and define the main part of the workflow. Typically it is required to retrieve additional data for the current object. You can do it by defining a newVariableand assigning it to the corresponding expression based on the context object.
To achieve it, perform the following steps:
- Define
Variablewith the nameCurrentObjectIdandVariable Type: Guid.
- Drag the Assign activity into the workflow and define the following values in the Properties toolbox:
To: Variable name (CurrentObjectIdin our case)Value: Target value (Item.IDin our case)
- Define the business logic that should be performed for every object.
For example, use theGetDataactivity to retrieve additional data based on the object identifier (CurrentObjectIdin our case) and use theCreate Taskactivity to create a task for the Administrator and provide all the required information about the affected object.