Multi-instance execution allows a connector activity to be repeated multiple times within a process.
Use multi-instance when:
- The same task must be performed for multiple users.
- A subprocess must be repeated for a collection of records.
- Multiple approvals are required.
- Multiple instances of a reusable process must be started.
- Similar work can be executed repeatedly without duplicating activities in the process diagram.
Instead of creating separate elements in the process diagram, a single element can be configured to create multiple instances automatically. For example, a process requires a document to be reviewed by three reviewers. Rather than creating three User Tasks, configure a single User Task as a multi-instance activity. The process creates one task for each reviewer automatically.
Studio Modeler supports two multi-instance execution modes:
| Execution Mode | Description |
|---|---|
| Sequential |
Sequential multi-instance execution creates and executes one instance at a time. The next instance starts only after the previous instance is completed. Use sequential execution when activities depend on the results of previous instances, resources should be processed one at a time, the system load should be minimized, or approval steps must occur in a specific order. |
| Parallel |
Parallel multi-instance execution creates multiple instances simultaneously. All instances can execute at the same time and are independent of one another. Use parallel execution when activities do not depend on one another, multiple users can work concurrently, faster process completion is required, or work can be distributed across teams. |
In the process diagram, multi-instance elements are displayed using three parallel lines at the bottom of the activity. The following is an example for the Microsoft Email connector:
| Icon | Explanation | Description |
|---|---|---|
|
|
No lines at the bottom at the bottom of the activity. | Multi Instance type set to None. |
|
|
Vertical lines at the bottom of the activity. | Multi Instance type set to Parallel. |
|
|
Horizontal lines at the bottom of the activity. | Multi Instance type set to Sequential. |
You can the Multi Instance Type of the activity when you click it in your diagram. The properties of the activity are then displayed in the Properties pane on the right.
Only when set to a value different than None, the following options are displayed.
Variables
Each multi-instance activity automatically provides the following variables:
| Variable | Description |
|---|---|
| nrOfInstances | Total number of instances created for the activity. |
| nrOfActiveInstances | Number of currently active instances. For sequential execution, this value is always 1. |
| nrOfCompletedInstances | Number of instances that have already completed. |
Each instance also has a local variable that is not visible outside that instance:
| Variable | Description |
|---|---|
| loopCounter | Index of the current instance within the multi-instance execution. |
Cardinality
Cardinality defines how many instances of the activity are created. The value can be specified as:
- A fixed number.
- A process variable.
- An expression that evaluates to a number.
For example, the cardinality value of 5 creates five instances of the activity.
Collection
A collection can be used to determine the number of instances by referencing a list of items. One activity instance is created for each item in the collection. For example: ["Document1", "Document2", "Document3"].
An element variable can optionally be specified. Each instance receives a single value from the collection through this variable. For example: document.
Completion condition
A completion condition can be defined to end the multi-instance activity early. When the condition evaluates to true, all remaining active instances are canceled and the multi-instance activity completes.
This can be useful when only a subset of instances needs to succeed before the workflow continues. For example, if the completion is achieved when 50% of instances are finished, the condition can be expressed as: nrOfCompletedInstances >= nrOfInstances / 2.
Results
A result collection can be configured to aggregate outputs from all instances into a single process variable after execution completes. After all instances complete, their output variables are aggregated into a single result collection in the parent process.
The result collection is a JSON array where each element is a map of variable name/value pairs from one sub-process instance:
[
{"variable": "foo", "updated": true},
{"variable": "bar", "updated": false}
]
The result element variable identifies which field or variable from each instance is added to the collection.