Reset For Each Step
  • 10 Feb 2021
  • 2 Minutes to read
  • Dark
    Light

Reset For Each Step

  • Dark
    Light

Article Summary

Overview

The following tutorial demonstrates how to use Reset For Each Step in Decisions. This step resets a For Each's loop iteration. This is important in cases when the Workflow process has to be designed to quit looping when the desired item is found.

In this example create a workflow process that contains a loop within another loop. Then apply breaking loop logic and compare results with or without Reset For Each Step.

Example

  1. Navigate to a Designer Project and click the CREATE FLOW button on the top Action bar.
    1. Select Flow, provide a Name, then click CREATE.
  2. From the Flow Designer, attach a ForEach step from the ITERATION category in the Toolbox tab, to the Start step.
  3. Select the ForEach step to navigate to its Properties tab. 
    1. Under DATA > Type, select String [Text] from the dropdown menu.
    2. Constant map a Collection of Strings (numerical values 1-9), making sure to keep each number on a separate line.
    3. Rename the OUTPUTS.
      Renaming data helps ensure conflict avoidance during later points of the design process. 
  4. Connect the Done path to the End step, and attach an additional ForEach Step to the Next path; this serves as the inner loop.
  5. Navigate to the Properties tab of the second ForEach Step.
    1. Select String [Text] from DATA > Type. Then, Constant map the numbers 9-1, in descending order. 
    2. Rename the OUTPUTS. 
  6. Attach a String Equals - Case Insensitive step from Toolbox > DATA > TEXT, to the Next path. 
    This step is used to search the second Collection to match the current Item from the outer loop. If Items are matched, the Flow leaves the inner loop and proceeds to the next Item in the outer loop Collection. 
  7. From the String Equals - Case Insensitive step's Properties, the Item from the first ForEach step to Value1 and the Item from the second ForEach to Value2

  8. From the FAVORITE STEPS category of the Toolbox, add a Show Popup step to the True path. 

    This step is used to display when Items from the loops are matched to one another.
  9. Under the Show Popup step's Properties, map the first Item to the Subject, and the second Item to Message

  10. Connect the Done path of the Show Popup step to the first ForEach Step. 

    This connection allows the Flow to leave the inner loop when Items and then continue to the next Item in the outer loop.
  11. Connect the False outcome of the String Equals - Case Insensitive step to the second ForEach step. 

    This allows the Flow to continue searching in the inner loop in the event that Items are not matched. 
  12. Connect the Done path of the second ForEach step to the first ForEach step. 

  13. Save the Flow.

  14. Select Debug from the top Action bar. 

    Note that the Flow runs successfully, but only 5 Notifications occur. This is due to a logic error caused by the Flow escaping the inner loop if Items are matched.

  15. Leave the Debugger. Then, from Toolbox > ITERATION, add a Reset ForEach Step.

    1. Detach the path connecting the Show PopUp step to the first ForEach Step.

    2. Attach the Done path of the ShowPopUp step to the Reset ForEach Step.

    3. Attach the Done path of the Reset ForEach Step to the first ForEachstep. 

  16. From the Properties of the Reset ForEach Step, select ForEach Step 1 from the ForEachStepToReset dropdown menu.

  17. Save the Flow, then if desired, close via X.



Debug

  1. From the Flow Designer, select the Debug link from the top Action bar.
  2. Click START DEBUGGING. 
    Note that the Flow runs successfully and that all 9 matched Items are displayed. This is because the inner loop was reset and escaped from each time a matched value occurred. 



Was this article helpful?