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

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.

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. 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

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

3 Likes

Just to note, this is mentioned in the walkthrough:

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’)

4 Likes

Here’s a PR to fix the issue:

2 Likes

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

2 Likes