Execute Workflows from Actions
Overview
You can execute workflows as a result of the UI action. This is a preferred way of executing custom business logic from actions because it allows defining custom business processes in the Workflow Studio without any coding. As an input the workflow takes a list of selected objects from the Action that can be used to retrieve additional information and process these objects in a sequence.
Creation of the Workflow
To be executed from an action, a workflow should meet the following criteria:
Integration Context: Action
Input Arguments
Name |
Direction |
Argument Type |
Default Value |
ObjectContexts |
In |
ObjectActionContext[] |
|
Where ObjectActionContext[] is a set of ObjectActionContext 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 ObjectActionContext to retrieve additional data for the corresponding object.
ObjectActionContext 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 event has been fired. |
User |
Guid |
Identifier of the user who triggers the action. |
To create a workflow for a compliance rule, perform the following steps:
1. Open the Workflow Studio and create a new workflow from the UI Action - WF Template template.
2. Define the Name, Icon, and Category for the workflow, and then click Save.
The integration Context should be Actions.
As a result, the system creates an empty workflow with predefined input arguments.
3. Drag the ForEach activity from the Repository toolbox and connect it to the Start activity.
4. In the Properties toolbox, click TypeArgument, and then select Browse for Types….
5. In the dialog, search for ObjectActionContext that appears, select ObjectActionContext, and click OK to confirm the selection.
6. In the Properties toolbox, select Values and then type ObjectContexts.
You can do the same by double-clicking the ForEach activity and using the extended activity designer.
7. Drag the Flowchart activity into the Body of the ForEach activity.
The Body of 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.
8. Double-click the Flowchart activity 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 new Variable and assigning it to the corresponding expression based on context object.
To achieve it, perform the following steps:
1. Define the Variable with the name CurrentObjectId and Variable Type: Guid.
2. Drag the Assign activity into the workflow and define the following values in the Properties toolbox:
To: Variable name (CurrentObjectId in our case)
Value: Target value (Item.ID in our case)
9. Define business logic that should be performed for every object.
For example, use the GetData activity to retrieve additional data based on the object identifier (CurrentObjectId in our case) and use the Invoke PowerShell activity to execute some script in context of the corresponding object.