Using Collection Sort StepLast Updated: 08/08/2016 Introduced in Verision: 2.0 |
This tutorial demonstrates how to configure and use Collection Sort Step. This step can be found under All Steps [Catalog] > Data > List category in the Flow Designer. With this step we can implement our desirable sorting logic for the collection of any existent type.
Example:
In this example we will use Collection Sort Step to sort Email Addresses in ascending or descending order.
We begin in the Designer Folder with clicking Create Flow on the Folder Actions Panel.
Then, we Name the Flow and click Create to proceed to the Flow Designer.
First, we are going to collect a list of Emails from All Accounts in our System. Add Get All step from Integrations > All Integrations > Internal Services > Account Service category.
Then, we are going to display all Emails to the User using a Form. We add Show Form step from the Favorite Steps category next to the Get All step in our Flow.
In the resulting window we Name the Form and click Create to proceed.
Our Display Accounts Form is designed as following… It will display a list of Email addresses using Simple List component from List category in the Toolbox. Also, it has two Button controls from Actions category allowing the User to choose Ascending or Descending Sorting. When finished, we can save our Form and close Form Designer.
Back in the Flow Designer we select the Show Form step on the workspace and map data for our List component:
For the ListOfEmails we configure Select Value Mapping type. Then, with Path picker we expand the Output from Get All step and pick Email Address collection. We can Ignore SelectedEmail field.
Next, we add Collection Sort Step from the All Steps [Catalog] > Data > List category on Sort Ascending outcome from our Show Form step.
We configure Collection Sort Step as following… Choose Select Value Mapping type for the InputCollection field, and using Path picker we select Email Address collection from the Get All outcome. Notice, that Collection Sort Step creates a Flow where we should configure our Sorting logic. We click Open Flow option.
This type of Flow has Start step with First Entity and Second Entity inputs (of your collection Type). Next, it has three End Steps: Entity First Sorts First, Entity Second Sorts First, Entity First and Second Sorted The Same. Between Start and End Steps we should build our sorting logic. The way this Flow works is following: It takes Item0 and Item1 from the Array, then runs these two Items through our sorting logic (set of Rules to compare these two Items), and based on our sorting results we configure the order of these two Items. Then, this Flow runs again but second time it sets Item0 in the array based on the first run and takes Item1 and Item2 from the array.
In this example our sorting logic will be based on the simple Rule: we will check which string should be placed first in Alphabetical order. We add Text AAlphabetically Comes Before TextB step from All Steps [Catalog] > Data > Text category.
Next, we configure Inputs to this Rule by Selecting Value of the FirstEntity for TextA and the Value of the SecondEntity for TextB.
Finally, we connect True outcome from the Rule to the Entity First Sorts First End Step and False outcome to the Entity Second Sorts First End Step. Then, we can save the Flow and close Flow Designer.
Back in our Main Flow, we add another Collection Sort Step on the Sort Descending outcome from the Form Step.
We configure InputCollection for this step in the same manner that we did for the first Collection Sort Step using Email Address collection from the Get All step outcome. Then, we click Open Flow option.
We are going to use the same Text AAlphabetically Comes Before TextB step from All Steps [Catalog] > Data > Text category for our sorting logic.
Again, we configure this Rule step in the exactly same way we configured this Rule in the first Collection Sort Step Flow.
This time we connect False outcome from the Rule to the Entity First Sorts First, and True outcome to the Entity Second Sorts First. In this way we implement our Descending sort logic. Save the Flow and close Flow Designer.
Back in our Main Flow, we are going to display sorting results to the User on another Form. We add Show Form step from the Favorite Steps category on the Sorting complete outcome from the first Collection Sort Step in our Flow.
Then, Name the Form and click Create to proceed.
This Form is designed as following:
It has a Title – Label component from the Data category, Simple List from the List category configured to display a List of Strings, and a Button control component from the Actions category. When we finished building our Form we can save it and close Form Designer.
Finally, we connect Sorting complete outcome from the second Collection Sort Step in our Flow to the Sorted Emails Form step. Then, we configure SortedEmails List on Sorted Emails Form by Selecting the Value of Sorted Array which will be an outcome either from first or second Collection Sort Step depending on User’s choice.
Then, connect Done outcome from the Sorted Emails Form step to the End Step in our Flow. This completes the Flow. We can click Debug Flow link on the top Panel of the Flow Designer to test our Flow.
Note that in Decisions version 3.5 and above, you’ll need to click Test Flow to access the Debugger.
The Flow runs in the Debugger and first Form displays an unsorted list of all Emails. We click Sort Ascending…
Second Form opens with a list of Emails sorted in Ascending order as designed.
Debugger Diagram indicates that the Flow ran with no issues.
We run the Flow again and this time we click Sort Descending on the first Form…
Second Form opens with a list of Emails sorted in Descending order. Click Done.
Again, Debugger Diagram indicates that the Flow ran with no issues.