- 19 Nov 2020
- 3 Minutes to read
- Print
- DarkLight
Processing Lists of Items with the Branching ForEach Step
- Updated on 19 Nov 2020
- 3 Minutes to read
- Print
- DarkLight
Overview
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 returns to the Branching ForEach Step at the Flow's end automatically.
Example
This example Flow will retrieve all user Accounts and display them by Email Address individually within a Form.
To begin, navigate to a Designer Folder and click the Create Flow button. Name the new Flow and click CREATE to open it in the Flow Designer.
Begin building the Flow by placing a GetAll component in the workspace from the Integrations > Internal Services > Accounts Service category by selecting the Done path of the Start step.
Next, place a Branching ForEach Step component, from the Flow Management category in the Steps panel.
The Branching ForEach step doesn't know which Input needs to be iterated over until it is specified on step. To configure this, click on the Branching ForEach step, then, under the Type drop-down, search for and select the Account data object.
Next, connect the GetAll step to the Branching ForEach step. Next, define what data is iterated by Select From Flow mapping the Output from the GetAll step (GetAll1_Output), to the Collection Input.
After defining the Branching ForEach step's Inputs, attach a Run Sub Flow step to the Done path. Then, from the Run Sub Flow step's Properties panel, under Advanced, select the Create link under Target to create a new Sub Flow; Name the Flow then select Create to enter the Flow Designer for the Sub Flow.
On the Start step's Properties Tab, select the Show Editor link located underneath Flow Input Data to begin defining the data that will be taken in from the Parent Flow. Name the Input and set the Type to Account, Select From Flow the Input to itself, then Close to save the Input definition.
Next, create a Form for displaying the user Account's Email Address; add a Show Form step from the Favorite Steps category in the Steps tab. Then, from the Show Form step's Properties tab, select the Pick or Create Form link, Name the Form then select Create.
In the Form Designer create a Form containing a Text Box component, a Label, and a 'Done' Button, and configure it as shown below. This Form will act as a vessel for the iterated EmailAddresses.
Save and Close the Form to return to the Flow Designer.
Next, define the Form's Inputs; under Assignment Type select Assigned and define the desired Account that will be used to go through the Email Forms. Name the Assignment and Assignment Action Name as desired. Then, under the Text Box's Input, Select From Flow map the EmailAddress from the Start step's Input as displayed below; this will simply display the Email for each iterated Account, on the Form.
Finally, connect the Done path of the Form step to the End step, Save and Close to return to the Parent Flow.
Next, from the Parent Flow, select the Run Sub Flow step and define its Input within the Sub Flow; Select From Flow the Output from the Branching ForEach step to the Input for the Sub Flow.
Since the ForEach step loops through each individual Account in the System, this will display the EmailAddress of each respective Account on each loop through, on the Form in the Sub Flow.
Finally, Merge the Output of each looped iteration of the Sub Flow, by adding a Merge step from the Flow Management category in the Steps tab and connecting the Merge Complete Path to the End step.
Save and Close the Flow to complete the Flow.
Debug
Test the Flow by accessing the Debugger in the Flow Designer via the Debug link located in the top toolbar of the Flow Designer; then, run the Flow in Full.
For each Account pulled from the system, a Form containing the Account's Email appears. Clicking Done directs control back to Branching ForEach Step 1, which then Outputs the next Account item until the collection is empty.
Once all Assignments have been completed (via each Assignee selecting Done), the Flow will Merge and complete.