
- 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
‎08-31-2020 11:49 AM
Hi Anand,
Is this design part of a topic, or part of a setup topic? If it is part of a topic, is this a guided process where the user would select an option, which would then prompt a related sub-option?
HR is setup differently than ITSM in that it uses a hierarchy structure (COE > Topic Category > Topic Detail > HR Service) to route the case appropriately to the correct resolution team. You also need to consider cross-scoping implications with RCA and make sure to use the HR VA scope if the topic will create a case.
The easier way to configure a category/sub-category experience (if using this in a topic) is to have your category, then use the decision utility to branch to the different sub-category options, which will in turn have their own flows. The end result will look more like a tree structure than have the dependency format.
You may also want to create separate topics depending on the complexity of the topic design.
Hope this helps.
Thanks,
Marcelle

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-01-2020 02:49 PM
Hello Marcelle, yes it is part of a topic and a guided process to let the user select options. I am using reference choice under user input section. Decision utility something which makes complex flow.
HR is one of the category and i wanted to show subcategory values which are depend on HR category. If i don't use the script i can able to show all sub categories but that doesnt help user to choose right sub-category. Does that make sense?

- 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 02:59 PM
Hello Mark, I have tried the same code earlier but it is not filtering any values nor it is showing anything. When i tried the same code in background script i get null object and if i use array variable i will get [Object, Object]. any other way to handle this situation?
Thanks
Anand