Mark Roethof
Tera Patron

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

LinkedIn

View solution in original post