August 12, 2022

Robotic Notes

All technology News

How to Create a Custom List Filter in Okta Workflows – Java Code Geeks

3 min read

Okta Workflows how-to guides are questions and answers from weekly community office hours, MacAdmins Workflows Slack channel, and other places. Read all previous how-to guides.

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:

Filtering a list with List – Filter card

But, this won’t 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 be included in the new (filtered) list.

Looking at the helper flow first, this is how it looks:

A flow (helper flow) to check if a list item matches a custom filter

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):

  1. Group name – that’s the actual group name such as No-code Builders
  2. 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 truethen the item should be added to the list
  • If the return value is falsethen 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.

Setting helper flow input

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 to 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).

Helper flow inputs

Source link