# How does the 'Add user to group through User Custom Field' script work?

**URL:** <https://meta.discourse.org/t/how-does-the-add-user-to-group-through-user-custom-field-script-work/241612>\
**Category:** Product Support\
**Tags:** automation\
**Created:** [September 26, 2022, 1:28am UTC](https://meta.discourse.org/t/how-does-the-add-user-to-group-through-user-custom-field-script-work/241612 "2022-09-26T01:28:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![leonardo](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/leonardo/32/228634_2.png) [@leonardo](https://meta.discourse.org/u/leonardo)\
**Post date:** [September 26, 2022, 1:41am UTC](https://meta.discourse.org/t/how-does-the-add-user-to-group-through-user-custom-field-script-work/241612/2 "2022-09-26T01:41:03Z")

</div>

Hi Nathan!

It’s meant for a rather specific use case where you want to ensure that users belong to a certain group based on a custom field that they filled in on signup.

Let’s say the custom field is “favorite soccer team” and it contains a list of choices. The script runs on a recurring trigger, so users will eventually end up belonging to a group with the same **full name** (not just `name`) as the value they chose, if the group exists.

You can look at the tests for some synthetic examples: [https://github.com/discourse/discourse-automation/blob/main/spec/scripts/add\_user\_to\_group\_through\_custom\_field\_spec.rb](https://github.com/discourse/discourse-automation/blob/main/spec/scripts/add_user_to_group_through_custom_field_spec.rb)

---

_[View the full topic](https://meta.discourse.org/t/how-does-the-add-user-to-group-through-user-custom-field-script-work/241612)._
