Reset For Each Step
- Updated on 07 Jul 2016
- 3 minutes to read
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.
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*.*
Name the Flow and click CREATE to proceed to the Flow Designer.
In the Flow Designer we add a ForEach Step from All Steps [Catalog] > Flow Management category.
With ForEach Step selected on the workspace in Data section of the step settings we pick String Type.
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.
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.
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 .
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.
Then, we are going to set up String Equals – Case Insensitive step. With this step selected on the workspace, we click Edit Input Mappings.
In the Mapping Editor we connect Item ONE tovalue1 and Item TWO to value2 . Then, we save and close Mapping Editor.
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.
Then, for the Message and Subject Inputs we Select value of Item ONE and Item TWO.
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.
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.
Back in the Flow Designer we add Reset ForEach Step fromAll Steps [Catalog] > Flow Management category next to Show Popup Step in our Flow .
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 .
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.