How to Add Users to Multiple Groups Based on Department Using Okta Workflows
Last Updated:
Okta Workflows can automatically add users to multiple groups based on their department by referencing a table that maps departments to groups. The department-to-group mapping is stored in a Workflows table with two columns — department and group — where a single department can have multiple rows, one for each group its users should belong to. Updating group assignments requires only editing the table, leaving all flows unchanged.
Automation Flow Architecture
The solution uses three flows that work together to look up each active user's department, find all associated groups, and add the user to each one.
The Department groups table maps each department to one or more Okta groups.
The three flows are:
- List users — lists active users and streams each one to the List groups flow.
- List groups — looks up the user's department in the table and returns all groups associated with it.
- Add to group — finds the group by name and adds the user to it.
The List Users Flow
The List users flow lists all active Okta users and passes each user to a helper flow.
The List users flow streams active users to the List groups helper flow.
How Does the List Users Flow Work?
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.
The 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.
List Groups Flow Steps
Set up the Helper Flow input fields, search the Department groups table, and iterate through the results to call the Add to group helper flow for each matching row by following these steps:
- The Helper Flow sets up the Record and State fields because the main flow uses streaming. The Record field contains the user's data. The flow extracts the user ID and the department directly from the Record object.
- The Table-Search Rows card searches the Department groups table for all rows where the department column equals the user's department.
- The List-For Each card iterates through the matching rows and calls the Add to group helper flow for each row, passing the group name and user ID.
The Add to Group Flow
The Add to group flow finds a group by name and adds the user to it.
The Add to group flow searches for the group and adds the user to it.
How Does the Add to Group Flow Work?
The flow receives the group name and user ID from the List groups flow, searches for the group, and adds the user to it using the following steps:
- The Helper Flow receives the Group name and User ID from the List groups flow.
- The Okta-Search Groups card searches for the group by name and returns the ID of the first matching group.
- The Okta-Add User to Group card adds the user to the group using the group ID and user ID.
