The Zurich release has arrived! Interested in new features and functionalities? Click here for more

How to call getDisplayValue method on results from GlideQuery?

Joseph Warner
Tera Guru

Is it possible to get the display value of a field for the result of a GlideQuery? I was hoping for something similar to a GlideRecord result, e.g., gr.getValue('state').getDisplayValue(), but I haven't found anything after much Googling.

1 ACCEPTED SOLUTION

Sandeep Rajput
Tera Patron
Tera Patron

@Joseph Warner You can use $DISPLAY Keyword concatenated with you column name to get the display value of a reference/choice field. For state you should 'state$DISPLAY' in select statement.

 

Here is the sample query to get State and assigned to display values from incident table.

 

 

var query = new global.GlideQuery('incident')
    .orderBy('number')
    .limit(5)
    .select('priority', 'state$DISPLAY','assigned_to$DISPLAY') //Returns a stream of records wrapped in a Stream object.  
    .toArray(100); //Terminal method in the Stream class that executes the query and returns the result.

gs.info(JSON.stringify(query, null, 2));

 

 

Here I have used $DISPLAY keyword with state and assigned_to field in the select statement.

 

    .select('priority', 'state$DISPLAY','assigned_to$DISPLAY') //Returns a stream of records wrapped in a Stream object.  

 

 

Here is the output.

 

Script: [
  {
    "priority": 1,
    "state$DISPLAY": "Closed",
    "assigned_to$DISPLAY": "Charlie Whitherspoon",
    "sys_id": "9c573169c611228700193229fff72400"
  },
  {
    "priority": 1,
    "state$DISPLAY": "On Hold",
    "assigned_to$DISPLAY": "Howard Johnson",
    "sys_id": "9d385017c611228701d22104cc95c371"
  },
  {
    "priority": 1,
    "state$DISPLAY": "In Progress",
    "assigned_to$DISPLAY": "Beth Anglin",
    "sys_id": "e8caedcbc0a80164017df472f39eaed1"
  }]

 

Hope this helps.

 

Source: https://docs.servicenow.com/en-US/bundle/vancouver-api-reference/page/app-store/dev_portal/API_refer...

View solution in original post

4 REPLIES 4

Brad Bowman
Kilo Patron
Kilo Patron

Hi Joseph,

Have you tried gr.getDisplayValue('state');?

@Brad Bowman , that was a good thought, but I tried that and it does not work.

Sandeep Rajput
Tera Patron
Tera Patron

@Joseph Warner You can use $DISPLAY Keyword concatenated with you column name to get the display value of a reference/choice field. For state you should 'state$DISPLAY' in select statement.

 

Here is the sample query to get State and assigned to display values from incident table.

 

 

var query = new global.GlideQuery('incident')
    .orderBy('number')
    .limit(5)
    .select('priority', 'state$DISPLAY','assigned_to$DISPLAY') //Returns a stream of records wrapped in a Stream object.  
    .toArray(100); //Terminal method in the Stream class that executes the query and returns the result.

gs.info(JSON.stringify(query, null, 2));

 

 

Here I have used $DISPLAY keyword with state and assigned_to field in the select statement.

 

    .select('priority', 'state$DISPLAY','assigned_to$DISPLAY') //Returns a stream of records wrapped in a Stream object.  

 

 

Here is the output.

 

Script: [
  {
    "priority": 1,
    "state$DISPLAY": "Closed",
    "assigned_to$DISPLAY": "Charlie Whitherspoon",
    "sys_id": "9c573169c611228700193229fff72400"
  },
  {
    "priority": 1,
    "state$DISPLAY": "On Hold",
    "assigned_to$DISPLAY": "Howard Johnson",
    "sys_id": "9d385017c611228701d22104cc95c371"
  },
  {
    "priority": 1,
    "state$DISPLAY": "In Progress",
    "assigned_to$DISPLAY": "Beth Anglin",
    "sys_id": "e8caedcbc0a80164017df472f39eaed1"
  }]

 

Hope this helps.

 

Source: https://docs.servicenow.com/en-US/bundle/vancouver-api-reference/page/app-store/dev_portal/API_refer...

@Sandeep Rajput, thank you for clarifying with a thorough example. Yes, the $DISPLAY flag was the solution.