
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2020 11:34 AM
Hello VA gurus,
I have a topic where user inputs a category field. I would like to add an option to users to select subcategory field as well but i want to show only those sub category fields which depend on category field. How do i make that happen? Below is the code and flow that i have created. Any suggestions/help will be much appreciated.
var options=[];
var choices = new GlideRecord('sys_choice');
//choices.addQuery('dependent_value','hr');
choices.addQuery('table', 'table');
choices.addQuery('element','u_subcategory');
choices.query();
while(choices.next()){
options.push({value: choices.value,label: choices.value});
gs.info(options);
}
Working code for Urgency is below:
Thanks
Anand
Solved! Go to Solution.
- Labels:
-
Virtual Agent

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2020 11:54 AM
Hi there,
The use of new GlideChoiceList is a nice one! Though actually... I don't know if there's a similar API for dependent values.
I don't have a set up currently for HR to my availability, so I will give an example based on incident.
I guess with the example working code for urgency, you can set up your own category code. Based on incident for example:
(function execute() {
var choices = new GlideChoiceList();
var choiceList = choices.getChoiceList('incident', 'category');
var options = [];
for (var i=0; i < choiceList.getSize(); i++) {
options.push({'value': choiceList.getChoice(i).getValue(), 'label': choiceList.getChoice(i).getLabel()});
}
return options;
})()
Looking for the dependent subcategory, again I don't know if there's a similar API, so scripted it in this case:
(function execute() {
var choices = new GlideRecord('sys_choice');
choices.addQuery('inactive', false);
choices.addQuery('dependent_value', vaInputs.category); // Rename this vaInputs to your Category user input
choices.addQuery('language', 'en');
choices.orderBy('order');
choices._query();
var options = [];
while(choices._next()) {
options.push({'value': choices.getValue('value'), 'label': choices.getValue('label')});
}
return options;
})()
(= tested, works)
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP
---
LinkedIn
Community article list
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 03:27 PM
That worked after making a small tweak on the query. Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2022 05:09 AM
Thanks mark it helped

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2020 03:27 PM
That worked after making a small tweak on the query. Thanks