How to check - if a specific value is present in the List type (Table field) from Catalog Client Script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 11:42 AM
Hi All,
I am working on ‘Service Catalog’ to order ‘Hardware’ (Laptop, Headset…etc) via referring “Hardware Model” table. On the catalog form I have a field “location” which is populated from table “cmn_location”. I want dropdown field should be populated with vales where location field matches in the “Hardware Model” table with field “u_country” (List type).
Table details:-
1. Locations (“cmn_location”)
2. Hardware Model (“cmdb_hardware_product_model”) - field “u_country” (List type).
3. Catalog form
Function (onchange) – location field. Here is my logic in Catalog Client Script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
//g_form.addInfoMessage('I am in Loading');
return;
} else {
//Clear all values/options from all Drop downs
g_form.clearOptions('Laptop_Select_Product');
//Include --None-- values
g_form.addOption('Laptop_Select_Product','--None--','--None--');
//1. Get values in Laptop Drop Down.
var gr1 = new GlideRecord('cmdb_hardware_product_model');
gr1.addQuery('status','In Production');
gr1.addQuery('u_category','Laptop');
gr1.addQuery('u_country','CONTAINS', g_form.getValue('location'));
gr1.query();
while(gr1.next()){
g_form.addOption('Laptop_Select_Product',gr1.name,gr1.name);
}
But all values are not populating as you can see
- Labels:
-
Service Catalog

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 12:06 PM
HI,
You should not use glide record in client script.
You have to move this code to Script include and use glide ajax. Also you should not use else loop. meaning this:
if (isLoading || newValue == '') {
//g_form.addInfoMessage('I am in Loading');
return;
} else {
It should be
if (isLoading || newValue == '') {
//g_form.addInfoMessage('I am in Loading');
return;
}
YOur code here
Thanks,
Ashutosh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2020 12:18 PM
Replace
gr1.addQuery('u_country','CONTAINS', g_form.getValue('location'));
with
gr1.addQuery('u_country','IN', g_form.getValue('location'));
Also, avoid using GlideRecord in Client side scripting as a best practice.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-01-2020 09:55 AM
Hi
i change the things - Using GlideAjax on Client side and calling Script include.
So client script looks like :---
var ga = new GlideAjax('ScriptIncludeCatalog_HardwareUtil');
ga.addParam('sysparm_name', 'myFunction_1');
ga.addParam('sysparm_status', "In Production");
ga.addParam('sysparm_u_category', "Laptop");
ga.addParam('sysparm_u_country', g_form.getValue('location'));
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
; }
Include Script part is :---
var ScriptIncludeCatalog_HardwareUtil = Class.create();
ScriptIncludeCatalog_HardwareUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myFunction_1: function()
{
var arr = [];
//alert('Server Side');
var gr1 = new GlideRecord('cmdb_hardware_product_model');
gr1.addQuery('status', "In Production");
gr1.addQuery('u_category', "Laptop");
gr1.addQuery('u_country', this.getParameter('sysparm_u_country'));
gr1.query();
while(gr1.next()){
arr.push(gr1.name);
}
return arr;
},
type: 'ScriptIncludeCatalog_HardwareUtil'
});
it is returning the value as well (i can see only 1 or 1'st value if it contains more then 1) but how parse the values and the main thing is How to Query so that i can find/compare the location value in the List type. List type field is having 2 values separated via , (like Singapore,India)
Any thing else i should try ??