Query a choice list by it's display value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 03:43 AM
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 ?
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 05:06 AM
What is the complete script you are using
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 05:18 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 06:00 AM
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
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 04:24 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2018 04:32 AM
It is a server side script (Script Include). I want to search records in a table.