for-each

The for-each Instruction executes a list of Instructions on nested records in an array in the input Record. This is used to iterate over multiple values in JSON input data.

action "for-each"
source The property in the input Record containing an array of nested records.
wrapValues (optional) If true, each element of the array is wrapped in an Object with the element as the value property. This is needed to iterate over arrays with simple values.
instructions An array of Instructions to be executed for each element in the input array.

When setting values within a for-each loop, remember to either add "multivalue": true to the Instruction or have a new/load instruction for the destination before setting a value on it so that values will not be overwritten as the array of instructions is executed multiple times.

Example

With an input record structured like:

{
    "username": "jbloggs",
    "supervisors": [
        {
            "supervisor": "jsmith",
            "role": "FIRST"
        },
        {
            "supervisor": "aturing",
            "role": "EXTERNAL"
        }
    ]
}

the supervisor could be applied to a multi-value property like:

{
    "action": "for-each",
    "source": "supervisors",
    "instructions": [
        {
            "source": "role",
            "destination": "project-supervisors",
            "name": "supervisorRole",
            "multivalue": true
        },
        // ...
    ]
}