- 03 Jun 2022
- 2 Minutes to read
- Print
- DarkLight
Using Collection Sort Step
- Updated on 03 Jun 2022
- 2 Minutes to read
- Print
- DarkLight
Overview
The Collection Sort step takes in a List of Items and will compare them in the Filter Flow. The Filter Flow will run these items through the sorting logic that was configured, and based on the logic will sort and configure the order of the list. This step can implement the desirable sorting logic for the collection of any existing type.
Example
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. This step can implement desirable sorting logic for the collection of any existing type. To download an example please navigate to Example Lab: Using a Collection Sort Step.
Begin in a Designer Folder, select Create Flow. Name the Flow then select 'Create'.
In the Flow Designer, add a Get All step from Integrations > All Integrations > Internal Services > Account Service.
Next, add the Collection Sort Step from the All Steps [Catalog] > Data > List.
Under Inputs > Input Collection, chose Select From Flow then chose GetAll_Output.All EmailAddress.
Notice that there is a Filter Flow this is where the sorted logic can be configured. The Filter Flow has a Start step with First Entity and Second Entity inputs (of your collection Type). It also has three End Steps: Entity First Sorts First, Entity Second Sorts First, Entity First and Second Sorted The Same. The way this Flow works is as follows: It takes Item0 and Item1 from the Array, then runs these two Items through the sorting logic (set of Rules to compare these two Items). Based on the sorting results, configure the order of these two Items. Then, this Flow runs again but the second time it sets Item0 in the array based on the first run and takes Item1 and Item2 from the array.
Select Edit to configure this flow.
For this example the sorting logic will be based on a simple Rule, that will check which string should be placed first in alphabetical order.
Add a Text AAlphabetically Comes Before TextB step from All Steps [Catalog] > Data > Text category.
Configure Inputs to this Rule by choosing the inputs for the FirstEntity by selecting TextA and then for the SecondEntity select TextB.
Note that Strings will be sorted according to ICU (International Components for Unicode)order, placing any Strings in the following order:
- Strings leading with numbers, placed in numerical order.
- Strings leading with special characters by ICU order.
- Strings leading with letters in alphabetical order.
For more information regarding ICU, see: International Components for Unicode.
Connect True outcome from the Rule to the Entity First Sorts First End Step and False outcome to another Text AAlphabetically Comes Before TextB step from All Steps [Catalog] > Data > Text category. Configure Inputs to this Rule by choosing the inputs for the FirstEntity by selecting TextB and then for the SecondEntity select TextA. Connect True outcome from the Rule to the Entity Second Sorts First End Step and the False outcome to the Entity First and Second Sorted The Same.
Then, save the Flow and close Flow Designer. Back in the main Flow connect the Done outcome path from the Collection Sort step to the End Step in the Flow.
Debug
Select Debug on the top panel of the Flow Designer to test the Flow.
The Flow runs in the Debugger. Select the Collection Sort Step, on Execution 1 chose View Input/Output Data. Within this dialog, the Inputs are visible as email addresses that are not sorted. Under the Outputs section, it is visible that the email addresses are sorted in alphabetical/ICU order.