Reset For Each StepLast Updated: 07/26/2016 Introduced in Verision: 3.2
This tutorial demonstrates how to use Reset For Each Step in Decisions. This step resets For Each 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 with 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 clicking Create Flow button on the Folder Actions Panel.
Then, we Name the Flow and click Create to proceed to the Flow Designer.
In the Flow Designer we add ForEach Step from All Steps [Catalog] > Flow Management category.
Next, we close Select Array window, because we are going to define Constant Array in this example.
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.
Again, we close Select Array window, because we are going to set up Constant collection for this step.
We define second ForEach Step in the similar manner we 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 we add Equals String – 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 Equals String – Case Insensitive step. With this step selected on the workspace, we click Show Mapping Editor.
In the Mapping Editor we connect Item One to value1 and Item Two to value2. Then, we save and close Mapping Editor.
Next, on True Outcome from Equals String – 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.
In the resulting window we check Show All Properties check-box.
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 Equals String – 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 Test 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 from All 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 click Test 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.