Dependent Select Box (Choice) Variables on Record Producers (+ Multi-language!)
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
Hi there,
You are working on a Record Producer, and specifically multiple Select Box (Choice) Variables and trying to make these dependent on each other. Similar like for example, Category and Subcategory within the Incident form on the Platform UI. There are some community posts or articles out there describing how to achieve this, though… these are not multi-language! And there's an important attribute needed to get this working on all instances.
In this article I'll share how to create dependent Select Box Variables and having the Choices Multi-Language. This will be done with Lookup Select Box uses. In a later article, I'll do the same using Catalog Client Script and Script Include. Using a Catalog Client Script and Script Include is more complex as Lookup Select Box Variables, though will have a better performance.
Dependent Choices
What we are basically after, is the same as for example Category and Subcategory within the Incident form on the Platform UI. When changing the Category, the choices for Subcategory dynamically change.
Category Variable
The first step would be setting up a Variable for the Category. This will be a Variable of type Select Box. We will be re-using actual choices from within the Platform through the Choice table and Choice field.
Subcategory Variable
The second step would be setting up a Variable for the Subcategory. This will be a Variable of type Lookup Select Box. As Lookup from table we will use the Choice [sys_choice] table and the Lookup value field will be the Label. Using the Reference qualifier we can then create the actual dependency between the Category and Subcategory Variable.
Depending on how you named your variables, the Reference qualifier could be something like:
javascript:'name=incident^element=subcategory^dependent_value=' + current.variables.category;
I did notice that this setup does not work on all instances. For example on my Personal Developer Instance this does work fine, though at one of our customers no go. Adding Variable attributes "ref_qual_elements=category" did the trick. Haven't found out yet why it does work on my PDI without the Variable attributes.
Multi-language Choices
When testing this setup on a Multi-language instance, you will notice that the Subcategory will show all choices available irrespective of the language of the logged-in user. An instance with for example English and Dutch language plugins would show:
To have the Subcategory only showing choices in the language of the logged-in User, we need to expand the Reference qualifier on the Subcategory slightly, adding:
"^language=' + gs.getUser().getLanguage()":
https://www.servicenow.com/community/developer-articles/dependent-select-box-choice-variables-on-record-producers-multi/ta-p/2296880