Query a choice list by it's display value

whitewalker
Kilo Contributor

I have a table with a field "Type". This field is a choice list where choices label and value are different. Ex:

Label - Value

Email - 1

DB - 2

CRM - 3

 

How do I use gliderecord to query this field by it's display value ?

 

14 REPLIES 14

Anurag Tripathi
Mega Patron
Mega Patron

you can use

 

gr.fieldName.getDisplayValue() 

or 

 

gr.fieldName.setDisplayValue() 

-Anurag

whitewalker
Kilo Contributor

I need to write a query like this:

var gr = new GlideRecord('tableName');

gr.addQuery('field display value', '=','email');

gr.query();

Just tried to run this

 

var gr = new GlideRecord('change_request');
gr.addQuery('sys_id', 'e2cdf552db252200a6a2b31be0b8f57f');
gr.addQuery('risk.label', 'high');
gr.query();
if(gr.next())
{
gs.print(gr.number);
}

 

It works

 

So you can use 

 

gr.addQuery('fieldName.label', 'Email');

-Anurag

it doesn't work on my instance.

if I do 

gr.addQuery('fieldName.label', 'Email');

gs.log(gr.getEncodedQuery());

it returns no records and in logs I get a message: "sys_idNotValidnull"