Processing Lists of Items with the Branching ForEach Step

Last Updated: 05/02/2018 Introduced in Version: 2.0

The Branching ForEach Step component iterates through every item in a collection, passing them to one or more next steps. It is similar to a non-branching ForEach Step component, with two major differences. It branches the flow into multiple paths, and the flows following a Branching ForEach Step do not need to complete the loop by forming a return path to the Branching ForEach Step component. The control of the flow will return to the Branching ForEach Step at the flow’s end automatically.

The Branching ForEach Step can be found in the Flow Management category of the Toolbox panel in the Flow Designer.

Example

This example flow will retrieve all of our user accounts and display them individually within a form, [Form] Display Names, which was created for this example.

 

2016-12-29_164612

 

To begin, navigate to a Designer Projects folder and click the Create Flow button. Name the new flow and click OK to open it in the Flow Designer.

 

 

Begin building our flow by placing a Get All component to the workspace from the Integrations > All Integrations > Internal Services > Accounts Service category of the Flow Designer’s startup window.

 

 

Also place a Branching ForEach Step component, from the cctagory All Steps [Catalog] > Flow Management. From the category Forms [Interaction] > [Current Folder], drag a [Form] Display Accounts component to the workspace.  This Form should have a Data Grid with the type of Account and a Button labeled Done. 

 

 

 

 

Our Branching ForEach step doesn’t know which input is to be iterated over until it is specified at that step. Click on the Branching ForEach step. To set the account object as the input type, from the Properties panel, Collection section, click the Type picker. Use the search field to locate “account,” select the Account data type, and click PICK.

 

 
 
 
Connect the Get All step to the Branching ForEach step.
 
Next, map the output of Get All, data for all of the system’s accounts, to the Branching ForEach step. Open the Mapping Editor by selecting the Branching ForEach Step and clicking the Edit Input Mapping link.
 
 
 

Conveniently, Get All has only one output, which we map to Collection as GetAll1_Output.

 
 
Connect the For Each path out of the Branching ForEach Step to the appropriate [Form] Display Accounts form.

Next, map the output from Branching ForEach Step to the appropriate [Form] Display Accounts input, so we select the form and click the Edit Input Mapping link.

 

 

In the Mapping Editor, we can see that there are five distinct inputs available to Display Accounts: a FlowConstantData object (Flow Data), System Constants, Lookup List Flow, an individual Account item (Item), and the entire collection of Account items (GetAll_Output). Since we want to iterate over each Account item individually, map Item to our input Data.

 

2016-12-29_161721
 

Now that our flow is complete, save and run it in our debugger.

For each account pulled from our system, a form containing the Account’s details appears. Clicking Done directs control back to Branching ForEach Step 1, which then outputs the next Account item, unless the collection is empty.

 

 

 2016-12-29_164612

Additional Resources