Reset For Each Step
  • Updated on 07 Jul 2016
  • 3 minutes to read
  • Print
  • Dark
    Light

Reset For Each Step

  • Print
  • Dark
    Light

This 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 Workflow process has to be designed to quit looping when desirable item is found.
Example
In this example we are going to create a simple workflow process that contains a loop within another loop. Then we are going to apply breaking loop logic and compare results with or without Reset For Each Step.
We begin in the Designer Folder with select theFLOW button*.*
2017-12-28_154745-1024x560.png

Name the Flow and click CREATE to proceed to the Flow Designer.
2017-12-28_154912-1024x615.png

In the Flow Designer we add a ForEach Step from All Steps [Catalog] > Flow Management category.
2017-12-28_155016-1024x768.png

With ForEach Step selected on the workspace in Data section of the step settings we pick String Type.
2017-12-28_155345-1024x768.png

Then, in Inputs Collection we define Constant Collection of Strings (1 through 9) . Also, rename Item and Item Index Outputs to avoid conflicts later in the workflow.
2017-12-28_155304-1024x768.png

On the Next outcome from the ForEach Step we add another ForEach Step from the All Steps [Catalog] > Flow Management category. This is going to be our inner loop.
2017-12-28_155500-1024x768.png

We define second ForEach Step in the similar manner we defined firstForEach Step , except Values for the Collection are in descending order (9 through 1) , and different names for Item and Item Index Outcomes .
2017-12-28_155844-1024x768.png

On the Next Outcome from the second ForEach Step we add String Equals – Case Insensitive step from the All Steps [Catalog] > Data > Text category. With this Rule Step we are going to search in second collection to match current item from the outer loop. If items are matched, we are going to escape our inner loop and proceed to the next item in the outer loop collection.
2017-12-28_160001-1024x768.png

Then, we are going to set up String Equals – Case Insensitive step. With this step selected on the workspace, we click Edit Input Mappings.
2017-12-28_160137-1024x269.png

In the Mapping Editor we connect Item ONE tovalue1 and Item TWO to value2 . Then, we save and close Mapping Editor.
2017-12-28_160221-1024x145.png

Next, on True Outcome from String Equals – Case Insensitive step we are going to add Show Popup step from the Favorite Steps category. With this step we will be able to see when our Items are matched.
2017-12-28_160436-1024x768.png

Then, for the Message and Subject Inputs we Select value of Item ONE and Item TWO.
2017-12-28_160606-1024x768.png

Next, we connect steps in our Flow as following… Done outcome from Show Popup step goes to the first ForEach Step (escaping inner loop when items are matched and continue to the next item in the outer loop) . False outcome from the String Equals – Case Insensitive step back to the second ForEach Step (items not matched, continue searching in the inner loop) . Done outcome from the second ForEach Step back to the first ForEach Step. Done outcome from the first ForEach Step to the End Step . Then, we click Debug Flow link on the top panel of the Flow Designer.
2017-12-28_160918.png

Flow executes in the Debugger with no issues, but we only see 5 Notifications instead of 9 . This is a logic error caused by escaping inner loop if items are matched. Close Flow Debugger.
2017-12-28_161203.png

Back in the Flow Designer we add Reset ForEach Step fromAll Steps [Catalog] > Flow Management category next to Show Popup Step in our Flow .
Reset-ForEach-Steo.jpg

Then, we select our second ForEach Step as ForEachStepToReset , and connect Done outcome from the Reset ForEach Step back to the first ForEach Step in our Flow . This completes our Flow . We can clickDebug Flow link on the top panel of the Flow Designer to test our Flow .
2017-12-28_162843-1024x295.png

The Flow executes with no issues in the Debugger . This time we can see all 9 Notifications because inner loop was reset and escaped each time our items matched.
2017-12-28_162942-1024x522.png

Was this article helpful?