Processing Lists of Items with the Branching ForEach Step
  • 11 Oct 2022
  • 3 Minutes to read
  • Dark
    Light

Processing Lists of Items with the Branching ForEach Step

  • Dark
    Light

Article Summary

Overview

The Branching ForEach step iterates through every item in a collection, passing them to one or more 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 Flow control automatically returns to the Branching ForEach step at the Flow's end.


Example

Note on Unexpected Validation Errors 
Using a Sub-Flow between the BranchForEach and Merge step is a required configuration. Failure to utilize one will cause the Designer to throw a validation warning. Thus, any Form following a Branch ForEach must not be In Flow but must be run via Sub Flow. 

This example Flow will retrieve all user Accounts and display them by Email Address individually within a Form.

  1. To begin, navigate to a Designer Folder and click the CREATE FLOW button. 
  2. Name the new Flow and click CREATE to open it in the Flow Designer.
  3. 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. 
  4. Next, grab a Branching ForEach step from the Flow Management category in the Steps panel.
  5. The Branching ForEach step doesn't know which Input needs to be iterated over until it is specified on the step. 
  6. To configure this, click on the Branching ForEach step, then, under the Type drop-down, search for and select the Account data object. 
  7. Connect the GetAll step to the Branching ForEach step. 
  8. Next, define what data is iterated by Select From Flow, mapping the Output from the GetAll step (GetAll1_Output) to the Collection Input. 
  9. After defining the Branching ForEach step's Inputs, attach a Run Flow step to the Done path. 
  10. From the Run Flow step's Properties panel, under Advanced, select the Create link under Target to create a new Flow.
  11. Name the Flow, then select CREATE to enter the Flow Designer for the Sub Flow. 
  12. On the Start step's Properties Tab, select the Show Editor link underneath Flow Input Data to begin defining the data taken in from the Parent Flow. 
  13. Name the Input and set the Type to Account, Select From Flow the Input to itself, then Close to save the Input definition. 
  14. Create a Form for displaying the user Account's Email Address.
  15. Add a Show Form step from the Favorite Steps category in the Steps tab. 
  16. From the Show Form step's Properties tab, select the Pick or Create Form link, Name the Form, then select CREATE.
  17. In the Form Designer, add a Text Box componenta Label with the text 'Your Email Address is', and an outcome Button
  18. This Form will act as a vessel for the iterated EmailAddresses.  
  19. Save and Close the Form to return it to the Flow Designer. 

  20. Next, define the Form's Inputs. Under Assignment Type, select Assigned and set the assigned user to admin@decisions.com. 
  21. Declare any text value for the Assignment Name and the Assignment Action Name
  22. Under the Text Box's Input, select From Flow to map the EmailAddress from the Account Input type. 
  23. This input will display the Email for each iterated Account on the Form. 
  24. Finally, connect the Done path of the Form step to the End step.
  25. Save and Close to return to the Parent Flow. 

  26. Select the Run Sub Flow step from the Parent Flow and define its Input within the Sub Flow.
  27. Use Select From Flow for the Output from the Branching ForEach step to the Input for the Sub Flow. 
  28. 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 the Form in the Sub Flow. 

  29. Merge the Output of each looped iteration of the Sub Flow by adding a Merge step from the Flow Management category or searching "Merge Step" in the Steps tab.
  30. Connect the Merge Complete Path to the End step.
  31. Save and Close the Flow to complete the Flow.

Debug 

  1. Test the Flow by accessing the Debugger in the Flow Designer via the Debug link located in the top toolbar of the Flow Designer. 
  2. This build will get a list of all the Accounts on the current system, iterate through the list by running the sub Flow for each list item, and assign an individual task to admin@decisions.com that displays the iterated lists email address in a Form.
  3. Once all Assignments have been completed (via each Assignee selecting Done), the Flow will Merge and complete.


Was this article helpful?