How to Add Users to Multiple Groups Based on Department Using Okta Workflows

In this guide:

Okta Workflows guides offer questions and answers from the Okta Workflows community office hours. They also come from the #okta-workflows channel on the Mac Admins Slack, as well as other places. Read all the other guides.

How do you add users to multiple groups based on their department using Okta Workflows?

This guide will teach you how to add users to multiple Okta groups based on their department using a Workflows table lookup.

Add Users to Multiple Groups Based on Department

You keep the department-to-group mapping in a Workflows table. The table has two columns: department and group. A department can have several rows, one for each group its users should belong to. To change which groups a department gets, you edit the table and leave the flows alone.

The Department groups table maps each department to one or more Okta groups
The Department groups table maps each department to one or more Okta groups.

The automation has 3 flows:

  1. List users: lists active users and streams each one to the List groups flow.
  2. List groups: looks up the user’s department in the table and returns all the groups associated with it.
  3. Add to group: finds the group by name and adds the user to it.

List users flow

The List users flow lists all active Okta users and passes each one to a helper flow.

The List users flow streams active users to the List groups helper flow.
The List users flow streams active users to the List groups helper flow.

How the flow works

  1. The Okta-List Users with Search card lists users with the Active status using the streaming option, passing each user to the List groups helper flow.

List groups flow

The List groups flow finds the groups for the user’s department in the table and calls a helper flow for each group.

The List groups flow searches the table by department and loops through the matching rows
The List groups flow searches the table by department and loops through the matching rows.

How the flow works

  1. Since the main flow uses streaming, the Helper Flow sets up the Record and State fields. The Record field contains the user’s data. The flow extracts the user ID and the department directly from the Record object.
  2. The Table-Search Rows card searches the Department groups table for all rows where the department column equals the user’s department.
  3. The List-For Each card goes through the matching rows and calls the Add to group helper flow for each one, passing the group name and the user ID.

Add to group flow

The Add to group flow finds a group by its name and adds the user to it.

The Add to group flow searches for the group and adds the user to it.
The Add to group flow searches for the group and adds the user to it.

How the flow works

  1. The Helper Flow receives the Group name and the User ID from the List groups flow.
  2. The Okta-Search Groups card searches for the group by name and returns the ID of the first matching group.
  3. The Okta-Add User to Group card adds the user to the group using the group ID and the user ID.

Okta Workflows resources

Leave a Reply