simon
October 10, 2023, 8:48pm
1
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:
Here’s a quick walkthrough of how to set up an Automation using the Add user to group through custom field option to automatically add people to groups depending on the User Custom Field they select at signup (or whenever they fill it out, depending on how you set your user custom field up):
Create the groups:
[create the groups]
The Automation script uses a group’s Full Name, so make sure you add one.
Create the User Custom Field:
[example user custom field] …
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
simon
October 11, 2023, 1:09am
4
Here’s a PR to fix the issue:
discourse:main
← scossar:feature-allow-either-user-field-name-or-user-custom-field-name-for-input
opened 01:07AM - 11 Oct 23 UTC
Currently the `add_user_to_group_through_custom_field` script expects the UserCu… stomField name to be used when the automation is triggered with the "Recurring" trigger, and the UserField name to be used when the automation is triggered by the "User first logged in" trigger. This is confusing for users. For both triggers, it would be better if the UserField name could be used. That's the name that is displayed on the Admin / Customize / User Fields page.
This PR attempts to fix the issue in a backwards compatible way, so that existing automations that are making use of the UserCustomField name (for example: 'user_field_5') will not be broken.
The PR also updates the "with one matching user" test to set the UserCustomField name in the way that Discourse sets the name - based on the UserField's id.
Related discussion on Meta: https://meta.discourse.org/t/add-user-to-group-script-has-different-field-input-for-the-two-triggers/281813
2 Likes
This has now been resolved with a new dropdown to select your existing User Custom Fields from, which works for both triggers:
committed 11:57PM - 26 Oct 23 UTC
New field to select user custom field. In addition, `add_user_to_group_through_c… ustom_field` script was adjusted to use the new component.
Also, data were migrated. Before they were not consistent.
Recurring script accepted text value which was user field identifier like `user_field_1`.
First logged in accepted text value which was user field name like `Title`.
2 Likes