Creating and configuring custom user fields

Creating a Discourse multiselect user field with many options

Entering dozens or hundreds of choices one at a time in Discourse’s custom user-field editor is tedious. I’ve been working on a multipurpose CLI tool for Discourse called dsc, which makes operations like this easier and more deterministic using local files. Just one of many things it can do is manipulate Custom User Fields.

dsc can create a new custom user field from a YAML file, including the entire ordered option list in one operation. The ucf command is an alias for user-field.

First, list your existing custom user fields:

dsc ucf list myforum --format yaml

This shows their IDs, types, options and settings.

Prepare the field

Create user-fields.yaml, replacing the source URL, question and options with your own. Make sure your YAML is valid - it’s easy to get wrong.

For example, here’s a country multiselect with 25 options:

version: 1
source: https://forum.example.org
user_fields:
  - name: Countries
    description: Which countries do you work in? Select all that apply.
    field_type: multiselect
    editable: true
    requirement: on_signup
    show_on_profile: false
    show_on_signup: true
    show_on_user_card: false
    searchable: false
    options:
      - Argentina
      - Australia
      - Brazil
      - Canada
      - China
      - Denmark
      - Egypt
      - France
      - Germany
      - India
      - Ireland
      - Italy
      - Japan
      - Kenya
      - Mexico
      - Netherlands
      - New Zealand
      - Nigeria
      - Norway
      - Singapore
      - South Africa
      - Spain
      - Sweden
      - United Kingdom
      - United States

This creates one field with 25 options, rather than 25 separate fields. You can extend the list as needed - I’ve used this approach successfully for a field with 250+ options.

Preview, create and verify

dsc ucf push --dry-run myforum user-fields.yaml
# Review the plan and the complete YAML file before applying.
dsc ucf push myforum user-fields.yaml
dsc ucf show myforum <field-id> --format yaml

Happy to get feedback on dsc including ideas for missing features. Create issues on the GH repo please.

2 Likes