# ‘Add user to group….’ script has different field input for the two triggers

**URL:** https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813
**Category:** UX
**Tags:** automation, completed, user-custom-fields
**Created:** [October 10, 2023, 8:48pm UTC](https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813 "2023-10-10T20:48:49Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 10, 2023, 8:48pm UTC](https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813/1 "2023-10-10T20:48:49Z")

</div>

Looking at the “Add user to group through User Custom Field” script, there seems to be a bit of an issue. If the “User first logged in” trigger is selected, the “User Custom Field name” input should be set to the _name_ of the User Field, for example “Native Language.” But if the “Recurring” trigger is selected, the “User Custom Field name” input needs to be set based on the User Field’s `id`. For example “user\_field\_5”.

Details about how to find the name for when the Recurring trigger is used are here: [Finding Userfield Custom Name for 'Add user to group through User Custom Field' - #2 by leonardo](https://meta.discourse.org/t/finding-userfield-custom-name-for-add-user-to-group-through-user-custom-field/241608/2).

Ideally, the friendly name (for example “Native Language”) would be used as the correct value for both of the available triggers. The relevant code is here: [https://github.com/discourse/discourse-automation/blob/main/lib/discourse\_automation/scripts/add\_user\_to\_group\_through\_custom\_field.rb](https://github.com/discourse/discourse-automation/blob/main/lib/discourse_automation/scripts/add_user_to_group_through_custom_field.rb). The way that the “User first logged in” trigger finds the correct User Custom Field from the field name (instead of the `id`) is here:

[https://github.com/discourse/discourse-automation/blob/main/lib/discourse\_automation/scripts/add\_user\_to\_group\_through\_custom\_field.rb#L54-L67](https://github.com/discourse/discourse-automation/blob/main/lib/discourse_automation/scripts/add_user_to_group_through_custom_field.rb#L54-L67)

Maybe there’s a backwards compatible way that logic could be applied to the Recurring trigger.

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [October 10, 2023, 9:22pm UTC](https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813/2 "2023-10-10T21:22:05Z")

</div>

Just to note, this is mentioned in the walkthrough:

> [@Add users to groups through custom field automation](https://meta.discourse.org/t/add-user-to-group-through-custom-field-automation/275873):
>
> bookmark This guide explains how to automatically add users to groups based on their selection of a custom user field during signup or profile update. person_raising_hand Required user level: Administrator Summary Create the necessary groups Set up a custom user field Create an automation to add users to groups Test the setup Creating the groups First, create the groups you want users to be automatically added to: Go to your site’s Admin area Navigate to Groups in the admin sidebar…

I’ve mentioned about reworking the script for consistency, though it’s not been prioritised yet. There’s also the `public user custom fields` and `staff user custom fields` admin settings that would be nice to bring into line with it as well.

(And there’s also `poll groupable user fields` too, which uses the ‘friendly name’)

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [October 11, 2023, 1:09am UTC](https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813/4 "2023-10-11T01:09:13Z")

</div>

Here’s a PR to fix the issue:

[https://github.com/discourse/discourse-automation/pull/225](https://github.com/discourse/discourse-automation/pull/225)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [November 3, 2023, 4:06pm UTC](https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813/5 "2023-11-03T16:06:20Z")

</div>

This has now been resolved with a new dropdown to select your existing User Custom Fields from, which works for both triggers: 🥳

[https://github.com/discourse/discourse-automation/commit/daa7f36481fd08f65bc029cef4839e6ecc235eb3](https://github.com/discourse/discourse-automation/commit/daa7f36481fd08f65bc029cef4839e6ecc235eb3)

---

<div class="post-metadata">

### Author: ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)
#### Post date: [November 3, 2023, 4:06pm UTC](https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813/6 "2023-11-03T16:06:23Z")

</div>


