Multiple Instance
A multi-instance activity is a way of defining repetition for a certain step in a business process. In programming concepts, a multi-instance matches thefor each construct: it allows execution of a certain step or even a complete subprocess for each item in a given collection, sequentially or in parallel.
A multi-instance is a regular activity that has extra properties defined (so-called multi-instance characteristics) which will cause the activity to be executed multiple times at runtime. Following activities can become multi-instance activities:
- Service Task
- Send Task
- User Task
- Business Rule Task
- Script Task
- Receive Task
- Manual Task
- (Embedded) Sub-Process
- Call Activity
- Transaction Subprocess
- nrOfInstances: the total number of instances
- nrOfActiveInstances: the number of currently active, i.e., not yet finished, instances. For a sequential multi-instance, this will always be 1
- nrOfCompletedInstances: the number of already completed instances
execution.getVariable(x) method.
Additionally, each of the created executions will have an execution-local variable (i.e., not visible for the other executions and not stored on process instance level) :
- loopCounter: indicates the index in the
for eachloop of that particular instance
multiInstanceLoopCharacteristics child element.
loopCardinality child element.
loopDataInputRef child element. For each item in the collection, an instance will be created. Optionally, it is possible to set that specific item of the collection for the instance using the inputDataItem child element. This is shown in the following XML example:
loopDataInputRef and inputDataItem is that 1) the names are pretty hard to remember and 2) due to the BPMN 2.0 schema restrictions they can’t contain expressions. We solve this by offering the collection and elementVariable attributes on the multiInstanceCharacteristics:
ASEE Flow Extensions
| Attributes | camunda:collection, camunda:elementVariable, camunda:asyncBefore, camunda:asyncAfter, camunda:exclusive, camunda:jobPriority |
|---|---|
| Extension Elements | – |
| Constraints | The camunda:exclusive attribute is only evaluated if the attribute camunda:asyncBefore or camunda:asyncAfter is set to true |
Boundary Events and Multi-Instance
Since a multi-instance is a regular activity, it is possible to define a boundary event on its boundary. In case of an interrupting boundary event, when the event is caught, all instances that are still active will be destroyed. For example, take the following multi-instance subprocess: Here all instances of the subprocess will be destroyed when the timer fires, regardless of how many instances there are or which inner activities are currently not completed yet.Loops
The loop marker is not natively supported yet by the engine. For Multiple Instance, the number of repetitions is known in advance - which makes it a bad candidate for loops anyway, as it defines a completion condition that may already be sufficient in some cases. To get around this limitation, the solution is to explicitly model the loop in your BPMN process: Be assured that we have the loop marker in our backlog to be added to the engine.JSON Collections with Multi-Instance Collections
JSON Arrays created with ASEE Flow SPIN can be used as a collection for multi-instance activities. Consider the following JavaScript example that initializes execution variablecollection:
collection variable in multi-instance activity’s camunda:collection extension element.
.prop() and .elements() to return the JSON array. Set the multi-instance activity’s elementVariable to a variable name that
will contain the array item. To access the value of the element, you can use .value() in your element variable.