Processing Lists of Items using ForEach Step
  • 03 Jun 2022
  • 1 Minute to read
  • Dark
    Light
  This documentation version is deprecated, please click here for the latest version.

Processing Lists of Items using ForEach Step

  • Dark
    Light

Article summary

Overview

The For Each Step passes individual items from a collection to a flow loop. The flow loop will then perform the same actions on each item. When every item has been processed, the loop forwards the finished collection to any subsequent steps outside of the loop.

Example

This example will get a list of all accounts, for each account, the flow will show a pop up displaying the account email and order number. Below is a downloadable example to import into Decisions.


Begin by navigating to a Designer Folder and select the Create Flow button.

2019-10-09_145003.PNG

Name the Flow and select 'CREATE' to open the Flow in the Flow Designer.

2019-06-25_1334.png

Begin building the new flow by first adding a GetAll step from the Steps panel under Integration > Internal Services > AccountService.

2019-12-20_114230.PNG

Next from the Flow Management category In the Steps panel, drag a ForEach step to the workspace. This will be used to process the list of accounts.

The ForEach step needs to know the data type of items it will process, it's important to note that the ForEach step can take in any data type. Select the ForEach step and in the Properties panel, under Data, select the appropriate Type, for this example the Type will be Account.

Under Inputs > Collection select the output from the GetAll step. The ForEach step will output Item and Item Index. Item is the single element of the array being iterated through. Item Index is the order number of that element starting at 0.

2019-12-20_114404.PNG

On the Next outcome path of the ForEach step add a Show Pop-up step from the Favorite Steps category in the Steps panel.

Under Inputs select Item.EmailAddress for the Subject. For Message select Item Index.Default. Direct the flow back to the ForEach step so that it can continue processing the rest of the collection.

2019-12-20_141558.PNG

This completes the Flow; save it and run it in the Debugger.

This is just one example of how the ForEach step can be used. Keep in mind the ForEach step can iterate through both default system data types and user-defined data types to perform any action in a ForEach loop.

2019-12-20_114740.PNG

The Flow runs in the debugger and shows a pop up for each account. Each pop-up displays the email address and the order number of that account.

2019-12-20_114843.PNG



Was this article helpful?