Dependent Select Box (Choice) Variables on Record ... - ServiceNow Community
Mark Roethof
Tera Patron
Tera Patron

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.

 

find_real_file.png


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;

 

find_real_file.png

 

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.

 

find_real_file.png


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:

 

find_real_file.png

 

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()":

 

find_real_file.png

Result

After having set up the Category and Subcategory Variables and having expanded the Reference qualifier, the result (in Dutch) should be something like below. A nice dependency between both variables and multi-language!

 

find_real_file.png

---


And that's it actually. Hope you like it. If any questions or remarks, let me know!

 

C

If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.

 

Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in?
- Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

 

Kind regards,


Mark Roethof

ServiceNow Technical Platform Architect @ Quint Technology

2x ServiceNow Developer MVP

2x ServiceNow Community MVP

---

LinkedIn

Comments
Alex Coope - SN
ServiceNow Employee
ServiceNow Employee

@Mark Roethof,

Nice write up,

Also instead of the addition to the ref_qual, you can also tick "unique values only" providing the "values" per language match, which will then render the choices that match the language of the user session

Mark Roethof
Tera Patron
Tera Patron

Hi Alex,

I did test a few weeks ago on Rome - Service Portal - Patch 1a, with lookup_unique checked, though no positive outcome with Lookup Select Box in combination with the Choice tabel selected.

Kind regards,
Mark

apjohn2
Mega Sage

Absolutely fantastic. Thank you for this!

SHARANsnow7
Tera Guru

Then how to depentent feild for  subcategory to category

angel kumari
Tera Contributor

one more requirement has miss guide i am not pick mandatory but its reflect in catalog item while test its in mandatory could u plz say why?  WhatsApp Image 2023-07-11 at 11.50.38 PM.jpeg

Ceci J
Tera Contributor

Thank You!! I've been trying to get this to work for 2 days!! Adding the variable attribute fixed it.  

anitha0887
Tera Contributor

HI @Mark Roethof 

 

below i need to add in catalog variable , how can i achive this requiment.

anitha0887_0-1714998528453.png

 

Mukesh Khanna P
Tera Expert

Hi @Mark Roethof I've implemented similar type of choice dependency to one of my record producer variable. It is working as expected in the service portal. But when the record producer is loaded in platform view of service catalog category, this variable is not showing any choice except "none", when the dependent variable is selected with any choice.

Any thoughts?

NarekH
Giga Explorer

Thank you very much for publishing this solution; it helped a lot!!!
I had to add "req_qual_elements=category" to have it work out.

Version history
Last update:
‎08-12-2024 09:08 AM
Updated by:
Contributors