Multi-instance variable aggregation

Multi-instance workflow executions allow a task or subprocess to be executed repeatedly, either sequentially or in parallel, for a dynamic number of items in a collection. A common use case is collecting input from multiple participants, such as reviewers providing feedback on a document or application.

By default, variables created or updated in each individual instance of a multi-instance execution are confined to a local scope. This prevents data clashes but makes it difficult to consolidate outputs from multiple instances into a single variable for subsequent use. The Variable Aggregations feature automates this process, enabling the collection, consolidation, and transformation of data from multi-instance executions efficiently.

Configuring variable aggregations

The Variable Aggregations feature is available in the Multi instance properties group of process elements that support multi-instance executions. It allows you to configure one or more aggregation definitions, mapping variables from individual executions to a single, structured target variable.

The configuration includes the following options:

Important considerations

The options for Target variable creation and the overarching variable retention policy represent important aspects of how data is handled in multi-instance loops.

The options for creating the target variable offer distinct behavioral patterns with significant implications for process design:

When variable aggregation is enabled, only data specified in the aggregation is retained after the multi-instance execution is completed. All other locally-scoped variables are discarded. This policy promotes a cleaner, more efficient process instance variable space by preventing clutter. To prevent data loss, ensure that all required data is explicitly defined in the variable Definitions.

Expressions in aggregation

Variable definitions support expressions, such as ${my_expression}, allowing for data transformations during aggregation. This centralizes data transformation logic in the process element, reducing the need for separate script or service tasks.

Example of aggregating feedback from multiple reviewers

Consider a review process with a user task that collects the input of reviewers, each with a name and a score weight. The task is executed for each reviewer in the collection, allowing them to provide a score and a comment.

  1. Multi-instance setup:
    • Multi instance type: Parallel.
    • Collection: This expression points to the collection variable created in a previous task, for example ${reviewers}.
    • Element variable: A temporary variable referencing the current item in the collection, such as reviewer.
  2. Variable Aggregations:
    • Target: reviews.
    • Type: Default.
    • Target variable creation: Default.
  3. Definition that maps the comment variable from the local instance to the comment key in the final JSON object.:
    • Source: comment.
  4. Definition that uses an expression to transform data. It multiplies the locally-scoped score by the scoreWeight from the reviewer element variable and divides by 100 to get a weighted score. This calculated value is then stored under the score key in the final JSON object:
    • Source: ${score * reviewer.scoreWeight / 100}.
    • Target: score.
  5. Definition that maps the name of the reviewer from the reviewer element variable to the reviewer key in the final JSON object:
    • Source: ${reviewer.name}.
    • Target: reviewer.

After all executions are completed, the aggregated variable reviews contains a JSON array with the consolidated data:

[
    { "comment": "Application looks good", "score": 90.0, "reviewer": "Jane" },
    { "comment": "Application looks perfect", "score": 80.0, "reviewer": "Jake" }
]

Conclusion

The Variable Aggregations feature simplifies process models by automating data consolidation and transformation. It eliminates the need for manual workarounds, reduces development effort, and minimizes errors. By centralizing logic in the process element, it promotes readability, maintainability, and scalability in workflows.