- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 11:24 PM
Hi All,
I am looking for help in identifying any issue with the following piece of Script Include code. I have two variable in 'Select location' (references to cmn_location table) and 'Select equipments' (Type-List collector (u_location_equipments)).
I have requirement to create reference qualifier on 'select equipments' variable based on 'select location'.For ex. If location is AC - FF – 001 then it should show only Projector, Video Conferencing Solution (WebEX), Table MIC.
I'm using below script include but it is not working,
----------------------------------------------------------------------------
var GetEquipments = Class.create();
GetEquipments.prototype = Object.extendsObject(AbstractAjaxProcessor, {
allEquipments:function(){
var include = '';
var selectedLoc = current.variables.select_location;
var equ = new GlideRecord('u_location_equipments');
equ.addQuery('u_location', selectedLoc);
equ.query();
while(users2.next())
{
include += (',' + equ.u_equipment);
}
//return criteria string
return 'sys_id IN' + include;
},
type: 'GetEquipments'
});
-----------------------------------------------------------------
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 02:15 AM
Resolved. Just need to write below line in "Select Equipments" reference qualifier,
javascript:'u_location='+current.variables.select_location

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 11:34 PM
I have found three bugs:
- Incorrect variable name in while loop
- Dot-walking in a while loop
- space in encoded query
I've also modified your code to use an array instead, as it is a bit tidier.
var GetEquipments = Class.create();
GetEquipments.prototype = Object.extendsObject(AbstractAjaxProcessor, {
allEquipments:function(){
//var include = '';
var include = []; // Use array, push() & join(",") instead
var selectedLoc = current.variables.select_location;
var equ = new GlideRecord('u_location_equipments');
equ.addQuery('u_location', selectedLoc);
equ.query();
// while(users2.next()) Bug #1 - wrong variable name
while(equ.next()) // replaced with equ
{
//include += (',' + equ.u_equipment); Bug #2 - dot walking in while loop
include.push(equ.getValue('u_equipment')); // use getValue instead
}
//return criteria string
//return 'sys_id IN' + include; Bug #3 - Erronerous space here
return 'sys_idIN' + include.join(","); // removed space
},
type: 'GetEquipments'
});
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-29-2019 11:45 PM
Hi Paul,
Thanks for the reply.
I updated the code but it is returning "No Matches found" when i set location as AC - FF – 001
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 12:37 AM
Hello Payal,
Just small change in code.
var GetEquipments = Class.create();
GetEquipments.prototype = Object.extendsObject(AbstractAjaxProcessor, {
allEquipments:function(){
//var include = '';
var include = []; // Use array, push() & join(",") instead
var selectedLoc = current.variables.select_location;
var equ = new GlideRecord('u_location_equipments');
equ.addQuery('u_location', selectedLoc);
equ.query();
// while(users2.next()) Bug #1 - wrong variable name
while(equ.next()) // replaced with equ
{
//include += (',' + equ.u_equipment); Bug #2 - dot walking in while loop
include.push(equ.getValue('u_equipment').toString()); // use getValue instead
}
//return criteria string
return 'sys_id IN' + include; Bug
},
type: 'GetEquipments'
});
Also try adding logs to check that you are getting the correct values in array and getrowcount as well
Please mark as Correct Answer/Helpful, if applicable.
Thanks!
Abhishek Gardade
Abhishek Gardade

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-30-2019 01:26 AM
Replace this line
include.push(equ.getValue('u_equipment')); // use getValue instead
with this line
include.push(equ.getValue('sys_id')); // use getValue instead
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022