- 18 Feb 2020
- 2 Minutes to read
- Print
- DarkLight
Reset For Each Step
- Updated on 18 Feb 2020
- 2 Minutes to read
- Print
- DarkLight
Overview
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 the Workflow process has to be designed to quit looping when desirable item is found.
Example
In this example create a simple workflow process that contains a loop within another loop. Then apply breaking loop logic and compare results with or without Reset For Each Step.
Begin in the Designer Folder with select Create Flow. Name the Flow and select CREATE to proceed to the Flow Designer.
In the Flow Designer, 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 pick String Type.
Then, in Inputs > Collection 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 add another ForEach step from the All Steps [Catalog] > Flow Management category. This is going to be the inner loop.
Define second ForEach step in the similar manner that was defined first ForEach 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 add String Equals – Case Insensitive step from the All Steps [Catalog] > Data > Text category. With this Rule step search in the second collection to match the current item from the outer loop. If items are matched, escape the inner loop and proceed to the next item in the outer loop collection.
Then, set up String Equals – Case Insensitive step. With this step selected on the workspace, select Edit Input Mappings.
In the Mapping Editor connect Item-first foreach to value1 and Item-second foreach to value2. Then, save and close Mapping Editor.
Next, on True Outcome from String Equals – Case Insensitive step add Show Popup step from the Favorite Steps category. With this step, we will be able to see when Items are matched.
Then, for the Message and Subject Inputs Select value of Item-first foreach and Item-second foreach.
Next, connect steps in the Flow as following. The 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). The 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, select Debug 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 the inner loop if items are matched. Close the Flow Debugger.
Back in the Flow Designer add Reset ForEach Step from All Steps [Catalog] > Flow Management category next to Show Popup step in the Flow.
Then, select the second ForEach Step as ForEachStepToReset, and connect Done outcome from the Reset ForEach step back to the first ForEach step in the Flow. This completes the Flow. Select Debug link on the top panel of the Flow Designer to test the Flow.
The Flow executes with no issues in the Debugger. This time see all 9 Notifications because the inner loop was reset and escaped each time the items matched.