How to populate values in reference variable based on one choice variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 12:25 AM
Hi Experts,
I have a requirement. I have two variables.
One is a choice type having two choices, A and B. I have another variable of type Reference, which is getting values from a custom table. I want to populate values in the second variable based on the selection of the first variable, which has two choices.
Since the second variable referred to a custom table, I can't edit that table to create a category where I will add choices A and B of variable one.
Is there any other way where I can use any scripting to achieve this?
Thanks in advance,
Amol
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 12:31 AM
Hi @Amol Pawar
You need to have a mapping or links between the choices values and the custom table. Without this, you cannot achieve your requirement.
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 12:50 AM - edited 04-30-2025 12:55 AM
Hello @Amol Pawar ,
You can achieve this through the Reference qualifier on the reference variable.
Say for example your choice variable is called "state" and has two options: "open" and "closed".
And in the reference variable you want to show Incidents that are either active or inactive, based on the first choice.
So your reference qualifier would be:
javascript: 'active=' + (current.variables.state == 'closed' ? 'false' : 'true');
Important: replace the : part with an actual colon character (:).
Just modify the above example based on your actual scenario.
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2025 12:52 AM
you will have to use script in script include and call it OR directly have script in advanced ref qualifier
something like this
Note: give correct choice value for A, B and the correct sysIds
javascript: var query='';
if(current.variables.firstVariable == 'choice value A')
query = 'sys_idINsysId1,sysId2'; // populate the 2 records which should be seen
else if(current.variables.firstVariable == 'choice value B')
query = 'sys_idINsysId3,sysId4'; // populate the 2 records which should be seen
query;
If you want to auto populate the reference variable based on option A or B selected then you can write onChange catalog client script on that drop down variable
something like this
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'choice A')
g_form.setValue('variable2nd', 'sysId1');
else if (newValue == 'choice B')
g_form.setValue('variable2nd', 'sysId2');
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader