Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Get list of choice field values with display values

Pradnya6
Giga Contributor

From a element descriptor I can get the dictionary elements of the field. I am using following code for the same.
var gr = new GlideRecord('cmdb_ci_ip_address');
gs.setLimit(1);
gr.query();
if (gr.next())
{
var choices = gr.getElement('ip_version').getChoices();
// need list of choice display values
}

Is there OOB function to get the display values list of a choice field?

5 REPLIES 5

avin3
Kilo Contributor

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]);
}