Add a For Each Action

You add a For Each action to execute another action for each item in an array. The action in the loop will be executed once for each item in the array.

To add a For Each action to an action chain:

  1. Open the Actions editor, for example, at the page level.
  2. Create an action chain, or open an existing action chain to add the action in the editor.
  3. Drag For Each from the Logic section of the Actions palette into the action chain.

    You can drag the action onto the Add icon ( Add icon ) in the action chain, or between existing actions in the chain.
    Description of foreach-add.png follows
    Description of the illustration foreach-add.png

  4. Configure the action's properties in the Properties pane:
    1. Update the ID field to make the action more easily identifiable.
    2. Click Assign next to Parameters to set up an expression for the items parameter that evaluates to an array, for example, $page.variables.ExpenseReportADP.data:


      The For Each action uses 'items' and the 'actionId' and adds a $current context variable for the called action to access the current item. You can inject additional properties into the available contexts for the called action to reference in its parameter expressions (as we'll see in subsequent steps).

    3. If you want to use your own context name, enter an alias for $current in the As field, for example, foo. This alias can then be referenced in nested called actions.
    4. Define whether your called actions must run serially (default) or in parallel. Regardless of the mode, the For Each action will not complete until the actions for each item in the items array are complete.
  5. Now click the Add icon ( Add icon ) inside the cycle loop and add the action you want to loop over the array. Here's an example that adds an action to call the PATCH /ExpenseReport/{ExpenseReport_Id} REST endpoint.


    When assigning the results of the REST call to a variable, you can use the following parameter expressions for the called action:
    Parameter Name Description
    $current.data The current array item.
    $current.index The current array index.
    alias.data An alternate syntax for $current.data, which allows a reference to $current from nested contexts.
    alias.index An alternate syntax for $current.index, which allows a reference to $current from nested contexts.

    For example, to pass the ID of the current expense report in the loop, you can use $current.index in the source expression:
    Description of foreach-assignparams-currentindex.png follows
    Description of the illustration foreach-assignparams-currentindex.png

    If you defined a context alias, for example, foo, you'd be able to create expressions that reference foo.data and foo.index:
    Description of foreach-asalias.png follows
    Description of the illustration foreach-asalias.png

    The outcome of the action is either "success", with an array containing the return value of the last action's results or "failure" if there is some exception/error.

  6. As a final step, click the Add icon ( Add icon ) to add an action (for example, a Fire Notification action) where the For Each action's loops ends.