Adding users to groups through custom field automation

:bookmark: This guide explains how to automatically add users to groups based on their selection of a user custom field during signup or profile update.

:person_raising_hand: Required user level: Administrator

Summary

  1. Create the necessary groups
  2. Set up a User Custom Field
  3. Create an automation to add users to groups
  4. Test the setup

Creating the groups

First, create the groups you want users to be automatically added to:

  1. Go to your site’s Admin area
  2. Navigate to Users > Groups
  3. Click “New Group” for each group you want to create
  4. Make sure to add a “Full Name” for each group, as the automation script uses this

:information_source: The automation script uses a group’s Full Name, so ensure you add one for each group.

Setting up the User Custom Field

Next, create a User Custom Field that users will select from:

  1. Go to your site’s Admin area
  2. Navigate to Users > User Fields
  3. Click “New User Field”
  4. Set up the field with appropriate options

Here’s an example of how your User Custom Field might look:

Creating the automation

Now, set up the automation to add users to groups based on their User Custom Field selection:

  1. Go to your site’s Admin area
  2. Navigate to Customize > Automations
  3. Click “New Automation”
  4. Choose a trigger:
    • “When a user first logs in” to add users to groups at signup
    • “Recurring” to run on a schedule, allowing users to change groups over time
  5. Select “Add user to group through custom field” as the action
  6. Choose your User Custom Field from the dropdown menu
  7. Configure the automation settings

Here’s an example of how your automation setup might look:

:mega: The automation now includes a dropdown to select your existing User Custom Fields, making setup easier and less prone to errors.

Testing the setup

To ensure everything is working correctly:

  1. Sign up as a new user or update an existing user’s profile
  2. Select an option from the User Custom Field you created
  3. Complete the signup or profile update process

Here’s an example of how the User Custom Field might appear during signup:

After the automation runs, you should see the user added to the appropriate group:

FAQs

Q: Can this automation add users to primary groups?
A: By default, this automation adds users to secondary groups. To set a group as primary, go to the group’s Manage > Membership settings page and select “Automatically set as primary group”.

Q: How often does the automation run if I choose the “Recurring” trigger?
A: You can set the frequency when creating the automation. Choose a schedule that best fits your community’s needs.

Q: What happens if a user changes their user custom field selection?
A: If you’ve set up a recurring automation, it will update the user’s group membership based on their new selection during the next run.

Additional resources

Last edited by @hugh 2024-07-16T02:47:08Z

Last checked by @hugh 2024-07-16T02:47:13Z

Check documentPerform check on document:
13 Likes

This Automation has now been tweaked to include a dropdown to select your existing User Custom Fields from. :partying_face:

No more rooting around in the user custom field json trying to find an id number, or any awkward typos snarling things up. Just super smooth and friendly UI. :sunglasses:

7 Likes

Pls the automation can only add users to the secondary group, what should I do if I want to add him to the primary group?

I think this would be set on the group’s Manage/Membership setting page where you can select ‘Automatically set as primary group’.

2 Likes