- 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-15-2023 07:52 AM
If I am not wrong, you can get right click in field and configure choice and see all drop down values.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 07:53 AM
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 09:37 AM
Hi Atulya,
This isn't a particularly helpful answer, no - I'm not talking here about choosing options in the ui, where it's clear that you can see the options; As I mentioned in the post, the goal is to be doing this through code for any table dynamically, since the integration I'm building will potentially be connecting to any and all of a customer's tables, and we want to display all of the choices in our UI for those particular kinds of fields.
Martin Ivanov gave a solid answer above - that's the one I'll be using. Thank you for your input nonetheless, though!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-15-2023 08:24 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