On to the question.
How to create a custom list filter?
Let’s say you want to get a list of all user groups in your organization that start with a particular text. For example you are looking for all groups that start with No-code.
This is not the right solution but I ran into this problem myself so I’m sharing it here. The first thing you will try is to use List – Filter card. Something like this:
But, this will not work. Let’s use a group name of No-code Builders for this example.
You want to check if No-code is
in No-code Builders group name. But instead, this card checks if No-Code Builders is
in No-code which results in an empty list.
The solution is to use List – Custom Filter card.
List – Customer Filter uses a helper flow to determine if a list item should or shouldn’t not be included in the new (filtered) list.
Looking at the helper flow first, this is how it looks:
The helper flow can contain any logic to determine if a current list time should or should not be included in a returned new list. If the helper flow returns a true – then the item will be added to a new list. If the flow returns false – then the time will not be added to the new list.
In this example, the main flow passes two variables to the helper flow (On Demand – Helper Flow card):
- Group name – that’s the actual group name such as No-code Builders
- Filter – text you are looking for in a Group name
The second card (Text – Find) takes the Filter text and searches for it in the Group name. If it finds a match, it returns its position which will be 0 or greater. If no match is found, then it will return -1.
The next card, True/False – Expression checks to see if the value is less than 0 and then negates it.
If a match is found (position = 0 or position > 0)
- (position < 0) evaluates to false
- not (position < 0) becomes true
If a match is not found (position = -1)
- (position < 0) evaluates to true
- not (position < 0) becomes false
The last card, Flow Control – Return returns true or false
- If the return value is true, then the item should be added to the list
- If the return value is false, then the item will not be added to the list.
This is the main flow calling the helper flow:
When you specify the helper flow, Group name and Filter variables will be shown.
Group name is set to Profile.Name (click on the down arrow on the right of the field). Profile.Name is a path in a JSON group list.
Filter is set to a text you are filtering for.
After running this flow, List – Custom Filter will return a list that contains only groups that have the filter text No-code in them.
To end the guide, this is how inputs from the main flow are related with the helper flow. You first define inputs in the helper flow. When you set a helper flow in the main flow (Helper Flow) those inputs will be shown (Group name and Filter).
Published on Java Code Geeks with permission by Max Katz , partner at our JCG program. See the original article here: How to Create a Custom List Filter in Okta Workflows
Opinions expressed by Java Code Geeks contributors are their own.