- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-10-2023 01:14 PM
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 11:38 AM
Hello. Here is a simple script that will retrieve data from the sys_choice table, where all the choice definitions reside.
In this example I am retrieving all active values of the state field on the inciden table.
var grChoice = new GlideRecord('sys_choice');
grChoice.addQuery('name', 'incident'); //replace 'incident' with your table
grChoice.addQuery('element', 'state'); //replace 'state' with your field name
grChoice.addQuery('inactive', false);
grChoice.addQuery('language', 'en') //replace dynamically if you have more than one language.
grChoice.query();
while(grChoice.next()){
gs.info('Choice value: '+ grChoice.getValue('value') + ' Choice label: '+ grChoice.getValue('label'));
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-12-2023 11:38 AM
Hello. Here is a simple script that will retrieve data from the sys_choice table, where all the choice definitions reside.
In this example I am retrieving all active values of the state field on the inciden table.
var grChoice = new GlideRecord('sys_choice');
grChoice.addQuery('name', 'incident'); //replace 'incident' with your table
grChoice.addQuery('element', 'state'); //replace 'state' with your field name
grChoice.addQuery('inactive', false);
grChoice.addQuery('language', 'en') //replace dynamically if you have more than one language.
grChoice.query();
while(grChoice.next()){
gs.info('Choice value: '+ grChoice.getValue('value') + ' Choice label: '+ grChoice.getValue('label'));
}
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2023 10:44 PM
@JordanUnito Did my answer help you resolve your issue? Do not forget to mark it as Correct.
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Martin Ivanov
ServiceNow MVP 2023, 2024
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 07:22 AM
Thank you Martin - this should work. didn't realize there was a separate table for it. Thank you!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 08:25 AM
From a element descriptor you can get the dictionary elements of the field. I am using following code for the same.
var gr = new GlideRecord('incident');
gs.setLimit(1);
gr.query();
if (gr.next())
{
var choices = gr.getElement('state).getChoices();
// need list of choice display values
}
------------------------------------------------------------
getChoices() method returns Java Array list. j2js() function helped to convert it to array. Saved me a lot of effort.
var glideRecord = new GlideRecord('incident');
glideRecord.query('priority','1');
glideRecord.next();
// urgency has choice list: 1 - High, 2 - Medium, 3 - Low, with value: 1, 2, 3
var choices = glideRecord.urgency.getChoices();
gs.info(choices);
var choiceList = j2js(glideRecord.urgency.getChoices());
gs.print(choiceList.length);
for (var i=0; i < choiceList.length; i++ ) {
gs.print (choiceList[i]);
}
hope this helps