Retrieve choice label not the value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 08:34 AM
I have a glide record where I am pulling the short description, update on and stage fields. The stage field I am having a problem with, it is giving me the value, but I really need to human readable label. What is the best way to accomplish this? This is all being done in the client script section of the UI Page. Here is my script:
for(var r = 0; r < requestsRITMs.length; r++)
{
var grRITMDetails = new GlideRecord('sc_req_item');
grRITMDetails.addQuery('number', requestsRITMs[r]);
grRITMDetails.query();
while(grRITMDetails.next())
{
var description = grRITMDetails.short_descritpion;
var date = grRITMDetails.sys_updated_on;
var stage = grRITMDetails.stage; // this is where I am getting the value not the label. I want the label...
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 09:10 AM
I get this error in the console:
grRITMDetails.stage.getDisplayValue is not a function(…)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:03 AM
Are you doing this from a client script? If so, you'll need to retrieve the information with GlideAjax rather than a GlideRecord call.
Docs: Client Scripts
Docs: GlideForm
Docs: GlideAjax
Client Script Best Practices - ServiceNow Wiki
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:35 AM
So I would need to write a script include, correct?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:47 AM
Yes, that can return you just about anything you like in a JSON string. An array of display values, objects, array of objects, you name it. GlideAjax is ultimate flexibility. Although not terribly timely in your case, we'll be doing the next TechNow on this topic on Dec 15.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-29-2016 10:53 AM
I wrote it up, this is what I scripted and works just fine in case anyone else runs into this issue:
Script Include:
var GetChoiceLabel = Class. create ( ) ;
GetChoiceLabel.prototype = Object.extendsObject (AbstractAjaxProcessor , {
getChoiceLabel : function ( )
{
var choiceLabel = '';
var grChoices = new GlideRecord('sys_choice');
grChoices.addQuery('value', this.getParameter( 'sysparm_user_name' ));
grChoices.query();
while(grChoices.next()) { choiceLabel = grChoices.label; }
return choiceLabel;
} ,
} ) ;
Client Script
var ga = new GlideAjax ('GetChoiceLabel');
ga.addParam ('sysparm_name', 'getChoiceLabel');
ga.addParam ('sysparm_user_name', "complete");//hard coded for testing
ga.getXML (GetChoiceLabelParse ) ;
function GetChoiceLabelParse (response ) { var answer = response.responseXML.documentElement.getAttribute ( "answer" ); alert (answer ); }