- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2017 12:05 PM
I know this is a bit of an odd question but is there a way to perform a query by the state label instead of the value? Using state.label does not work. (I'm well aware that using the value is by far the safest.)
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-31-2017 02:48 PM
You can try what Shishir has suggested. Or try this
- var inc = new GlideRecord('incident');
- inc.addQuery('state',getState('incident','New'));
- inc.query();
- while (inc.next()) {
- gs.print('-----------'+inc.number);
- }
- function getState(tablename,label)
- {
- var ch = new GlideRecord('sys_choice');
- ch.addQuery('name',tablename);
- ch.addQuery('label',label);
- ch.query();
- if (ch.next())
- {
- return ch.value;
- }
- }
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2017 12:18 PM
Hi Jim,
Yes, You can query based on display Value. Try something like below using CONTAINS. it worked for me.
var inc = new GlideRecord('incident');
inc.addQuery('category','CONTAINS','Request');
inc.query();
while (inc.next())
{
gs.addInfoMessage('-----------'+inc.number);
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2017 01:17 PM
Thank you for taking time to reply. I'm looking specifically for the 'state' field and this does not seem to work. (Where state of New is a valid label)
var inc = new GlideRecord('incident');
inc.addQuery('state','New');
inc.query();
while (inc.next()) {
gs.print('-----------'+inc.number);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-29-2017 02:01 PM
You can use getChoiceValue(); to get the label for the choice field, but querying the table always works with the name, value pairs.
Hope to see some method like this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-30-2017 11:36 PM
You didnt use contains. Use below script
- var inc = new GlideRecord('incident');
- inc.addQuery('state','CONTAINS','New');
- inc.query();
- while (inc.next()) {
- gs.print('-----------'+inc.number);
- }
Please mark this response as correct or helpful if it assisted you with your question.