Avoid Unexpected Results With Branch For Each Step
- Updated on 25 Nov 2015
- 7 minutes to read
This tutorial demonstrates how to avoid unexpected results while using Branch For Each step.
In this example we are going to demonstrate unexpected results that may occur using Branch For Each step. Then, we are going to demonstrate how to avoid these unexpected results.
We begin in the Designer Folder by clicking Create Flow on Folder Actions Panel.
Then, we Name our Flow and click Create to proceed to the Flow Designer.
First, in the Flow Designer we add Get All step from the Integrations > All Integrations > Account Service category.
Then, next to Get All step in our Flow we add Branch For Each step from All Steps [Catalog] > Flow Management category.
In the resulting window we define Account Type for the Branch For Each step.
After we have defined Type , we should be able to define Collection Input for the Branch For Each Step . We Select Value of theGetAll_Output.
When Branch For Each step configured, we can click Done .
Next, on theFor Each outcome from the Branch step we addShow Form step from the Favorite Steps category.
In the resulting window we Name our Form and click Create to proceed to the Form Designer.
For the simplicity of this example we designed our Form as following… We have a Label that is configured as Variable and a Button to complete the Flow . When finished, we can save the Form and close Form Designer.
Then, we select our Form on the workspace and change the Assignment Type fromIn Session to Assigned .
Next, we click Show Mapping Editor for this step.
In the Mapping Editor we expand Item outcome from the Branch For Each step and connect AccountID to AccountsAndGroups and DataToDisplay fields. So for each account in the System we are going to assign a Form that displays its Account ID . When finished, we can save and close Mapping Editor.
Then, we are going to add another copy of the Form that we created in previous steps next to the first Form in our Flow .
We change the Assignment Type on the second Form to Assigned .
Then, we click Show Mapping Editor…
In the Mapping Editor we expand Item outcome from the Branch Step and map data as following. This Form is going to be Assigned to the same account as first Form but will display Email Address instead of AccountID . When finished, save and close Mapping Editor.
Back in the Flow Designer we add Merge Step from the All Steps [Catalog] > Flow Management category.
Mention, that our Branch Step has a validation warning that says that we should encapsulate all steps between Branch and Merge steps into a Linked Flow . If we ignore this warning, we may end up with unexpected results.
Let’s Debug our Flow to see the results…
Note that in Decisions version 3.5 and above, you'll need to click Test Flow rather than Debug Flow .
The Flow runs in the Debugger and first Form is being assigned to our current account. In the pop-up window we click No to ignore the Assignment .
In the Home Folder we can find the first Assigned Form . We click it and choose to Fill It In.
The Form displays our Account ID and we submit this by clicking Done .
Second Form is being assigned to us, and we click Yes to Fill In The Form .
Second Form displays our Email Address as expected. Click Done to complete the Assignment .
Then, we Log Out and Log back in as a different user.
In the Home Folder we locate First Assigned Form and Fill It In.
Again, as expected, our Form displays our Account ID . We click Done to submit.
Next, we expectSecond Form with our Email Address to be Assigned to us but this is not happening.
We test another Account and see the same behavior… First Form is Assigned . After First Assignment completion Second Form is not being Assigned . We go back to the initial account… In the Home Folder we can see two newAssigned Forms … These are the Second Forms that should be Assigned to other Accounts .
Next, we are going to fix this issue by encapsulating our Forms into a Linked Flow.
In the Designer Folder we click Create Flow on the Folder Actions Panel.
Then, we Name the Flow and click Create to proceed to the Flow Designer.
In the Flow Designer we select Start Step on the workspace and click Add New Flow Input.
We know, that both our Forms need to use Item (Account) output from theBranch Step. Therefore, we add a variable of Account type as Flow Input.
Then, we simply add our Form from the Flows, Rules, Forms, and Reports > Forms [Interaction] > [Current Folder] category.
Next, we add another copy of our Form next to the First Form in the Flow . Connect the outcome from the Second Form to the End Step in the Flow .
Then, we select First Form on the workspace, changeAssignment Type to the Assigned and click Show Mapping Editor.
In the Mapping Editor we map data in the same manner we did in the Main Flow for the First Form but here we are using Account Flow Input instead of Item . Save and close Mapping Editor when finished.
Next, we select Second Form on the workspace, change Assignment Type to Assigned , and click Show Mapping Editor.
In the Mapping Editor we expand Account Flow Input , connect Account ID to Accounts and Groups field, and Email Address to the Data To Display field. Save and close Mapping Editor.
This completes our Linked Flow . Save the Flow and close Flow Designer.
Back in the Designer Folder we locate our Main Flow and Edit it.
In the Flow Designer we remove connections To and From our Form steps. Then, on the For Each outcome path from the Branch For Each step we add our Linked Flow from the Flows, Rules, Forms, and Reports > [Current Folder] category.
Then, connect Done outcome from the Linked Flow to the Merge Step . Select Linked Flow Step and Select Value of Item outcome from the Branch Step as Account Input to this step.
We can delete our old Form Steps from the workspace.
Mention, that Branch For Each step does not haveValidation Warning . We can test our Flow now. Click Debug link on theTop Panel of the Flow Designer.
Our Flow runs in the Debugger and just like the first time First Form is being Assigned to us and we ignore it by clicking No .
Then, we navigate to the Home Folder , locate the First Assigned Form and Fill It In … The Second Form is being Assigned to us after we Complete First Form … We fill in the Second Form.
Then, we Log Out and Log back in as different User . In the Home Folder we locate First Assigned Form andFill It In …
We complete the Form …
And Second Form is being Assigned to us right away as expected.
Second Form displays our Email Address … We click Done to complete the Assignment .
When we log back in as initial Account , we can see that our Flow Assigned all Forms as we designed and no unexpected results present.