Overview
This KB will teach you how to search for users using contains in Okta Workflows.
Solution
The KB shows how to search for users, but other record types can also be searched.
Search using the ‘co’ (contains) operator
The following example shows searching for users using the co operator (contains):
Searching using the ‘co’ operator.
The card returns all users containing okta.com in their email attribute:
Searching with the ‘co’ operator.
Note that okta.com can be anywhere in the email string, for instance as in aaron@okta.com.email.
From the Okta developer docs, you can use co only the following user profile attributes:
You can only use
cowith these select user profile attributes:profile.firstName,profile.lastName,profile.email, andprofile.login.
When searching for groups, the co operator supports the following attributes:
You can only use
cowith these select profile attributes:profile.nameandprofile.description
To learn more about the contains operator, refer to Okta’s API Documentation.
Search using ‘contains’ with a helper flow
We published this section as a workaround before the ‘co’ operator became available. We are keeping this section as an alternative solution and example when you need to search using other attributes.
This section will show you how to build a solution for searching for text using contains.
The solution has two flows:
- List Users.
- Search Contains_Helper.
List Users flow
This is the List Users flow:
NOTE: The List Users with Search card uses the First 200 Matching Records option. This solution will not work with the Streaming option.
The flow has the following steps.
- Okta – List Users with Search card returns all the Okta users.
- The flow passes the users to the List—Filter Custom card. The Filter Custom card uses a helper flow to review each item in the list. The helper flow has logic to search using ‘contains’. The Filter Custom card returns a list of the items that contain the search text.
Search Contains_Helper flow
This is the helper flow.
A flow to search with contains.
The flow has the following steps.
- Helper flow. The main flow passes each User record to the Helper Flow card. The Helper Flow defines a User record Email property instead of using the Object – Get card to get a property.
- The flow uses the Find card to search for contains. In this example, the flow searches for okta.com text in the Email field. The Find card returns the position (
0is the first position) where the string starts or-1if no match is found. - The True/False – Expression card checks if a text is contained within another string. If the email ends with okta.com, the Expression card returns true. Otherwise, it returns false.
- The flow passes a true or false value from the previous card to the Return card. If the return value is true, include the current record (User) in the result list. This means the search found a match. If the return value is false, don’t include the current record in the result.
Result
The Okta instance has nine users. Two of them have an okta.com email address. When the flow is run, it finds two matches since two users have an email address with okta.com. The list field in the Filter Custom card holds a list with two records.
The list field holds the result.
Result with two records:
Result with two records where the email has the text okta.com.
Related References
- Search for Users using Custom Search Criteria in Workflows.
- How To Search for Groups Using Custom Search Criteria in Workflows.
