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

What is the complete script you are using

-Anurag

var gr = new GlideRecord('tableName');

gr.addQuery('u_type.label','email');

gr.query();

 

I think that your script is working because in your system, you have the property "glide.invalid_query.returns_no_rows" set to false and the invalid part of your query (gr.addQuery('risk.label', 'high');) is ignored. Try to remove gr.addQuery('sys_id', 'e2cdf552db252200a6a2b31be0b8f57f'); from your query and see what it returns. I think it will return all record.

 

 

Yea, you are right, 

 

can you use something like this

 

gr = new GlideRecord('tableName');

gr.query();

while(gr.next())

{

if(gr.u_type.getDisplayValue()=='Email')

{

//Do Something

}

}

-Anurag

Bhawana Upreti
Tera Guru

Hello,

This script might help you.

var choiceValue = g_form.getValue('u_type'); //Here replace u_type with the exact column name of the field you want

var choiceLabel = g_form.getOption('u_type', 2).text;

alert(choiceLabel);

 

It will give you output: DB. 

 

Let me know if you find any issue.

 

Thanks.

whitewalker
Kilo Contributor

It is a server side script (Script Include). I want to search records in a table.