OVERVIEW
This article will teach you how to set up a custom sort in Okta Workflows.
SOLUTION
Let’s look at an example using the List-Sort card before setting up a custom search.
Basic Sort
Okta Workflows provides the List-Sort card to perform a basic sort: sort a list from smallest to largest.
Let’s say you have the following object list and need to sort the list by number of employees.
[
{
"departmentName": "Sales",
"location": "New York",
"employees": 50
},
{
"departmentName": "Marketing",
"location": "San Francisco",
"employees": 30
},
{
"departmentName": "Engineering",
"location": "Austin",
"employees": 100
},
{
"departmentName": "Customer Support",
"location": "Chicago",
"employees": 40
},
{
"departmentName": "Legal",
"location": "Boson",
"employees": 10
}
]
The following flow sorts the list using the employees value from smallest to largest.
Sort with the List-Sort card.
The flow has the following steps:
- The Text-Compose card creates the JSON list as text.
- The JSON-Parse card converts the text into a JSON object.
- The List-Sort card sorts the list using the employee value from smallest to largest.
Result after sorting the list:
Result sorting with the List-Sort card.
Custom Sort
The List-Sort Custom card can be used to define a custom search.
For instance, let’s say you want to sort the following text using the length of each word so the word we is first and the word automation is last.
[
"we",
"build",
"identity",
"automation",
"using",
"okta",
"workflows"
]
Main Flow
The main flow looks similar to the flow in the first example, except the List-Sort Custom card sets up a helper flow.
Flow with List-Sort Custom card.
The flow has the following steps:
- The Text-Compose card creates the JSON list as text.
- The JSON-Parse card converts the text into a JSON object.
- The List-Sort Custom card calls a helper flow for a custom sort.
Helper Flow
This is the helper flow:
Helper flow for custom sort.
The flow has the following steps:
- The main flow passes each text item into the helper flow in the On Demand-Helper Flow card.
- The Text-Length card returns the length of each word in the list.
- The Flow Control-Return card returns the length of each word in the list. Workflows uses the length number to then sort the list.
You do not perform the actual sorting. A position number is returned, and Workflows uses that number to sort the list.
Running the Flow
Running the flow will sort the list using each word's length. The original list order is also visible in the JSON-Parse card.
List sorted with custom sort.
Another Custom Sort Example
Returning to the first example, let's say you want to sort the list using the employees' values, but now, go from largest to smallest instead of using the built-in smallest to largest sort.
Main Flow
Custom sort main flow.
The helper flow uses the Number-Formula card to negate the employees value to reverse the sort order:
Custom sort helper flow.
The sort results when running the flow:
Custom sort result.
RELATED REFERENCES
- How To Search for Groups Using Custom Search Criteria in Workflows
- How to Create a Custom List Filter in Workflows
- Search for Users using Custom Search Criteria in Workflows
