Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Reference qualifier for list collector via script include does not work

Payal5
Kilo Expert

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.

find_real_file.png

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'
});

-----------------------------------------------------------------

 

find_real_file.png

 

1 ACCEPTED SOLUTION

Payal5
Kilo Expert

Resolved. Just need to write below line in "Select Equipments" reference qualifier,

javascript:'u_location='+current.variables.select_location

View solution in original post

9 REPLIES 9

The SN Nerd
Giga Sage
Giga Sage

I have found three bugs:

  1. Incorrect variable name in while loop
  2. Dot-walking in a while loop
  3. 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

Payal5
Kilo Expert

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

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

Thank you,
Abhishek Gardade

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