- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 12:25 PM
I'm not getting the results I'm expecting from my queries. the following code is attempting to return a business service and it's associated admin portals from a cross reference table I created. the first pass works as expected, all other passes do not.
var Scontract = new GlideRecord('ast_service'); // validation record for Service Contract
var BusXref = new GlideRecord('u_bus_service_portal_xref'); // Cross reference table for business service to portal(s)
if (existingCAN == true){
Scontract.addQuery('u_can', can.sys_id);
Scontract.query();
while (Scontract.next()) {
BusXref.addQuery('u_bus_service',Scontract.getValue('u_business_service'));
BusXref.query();
while (BusXref.next()) {
var u_portal = BusXref.getDisplayValue('u_portal');
PortalX.push(BusXref.getDisplayValue('u_portal'));
}
}
var arrayUtil = new ArrayUtil();
arrayUtil.unique(PortalX);
}
the results I'm expecting:
business service 1
portal 1
portal 2
business service 2
portal 1
portal 3
The results I'm getting
business service 1
portal 1
portal 2
business service 2
suggestions ?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 12:38 PM
Try:
var Scontract = new GlideRecord('ast_service'); // validation record for Service Contract
if (existingCAN == true){
Scontract.addQuery('u_can', can.sys_id);
Scontract.query();
while (Scontract.next()) {
var BusXref = new GlideRecord('u_bus_service_portal_xref'); // Cross reference table for business service to portal(s)
BusXref.addQuery('u_bus_service',Scontract.getValue('u_business_service'));
BusXref.query();
while (BusXref.next()) {
var u_portal = BusXref.getDisplayValue('u_portal');
PortalX.push(BusXref.getDisplayValue('u_portal'));
}
}
var arrayUtil = new ArrayUtil();
arrayUtil.unique(PortalX);
}
Note Line 7 was moved because otherwise, you're just adding more and more query conditions to an existing GlideRecord object and will get no matches.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 12:38 PM
Try:
var Scontract = new GlideRecord('ast_service'); // validation record for Service Contract
if (existingCAN == true){
Scontract.addQuery('u_can', can.sys_id);
Scontract.query();
while (Scontract.next()) {
var BusXref = new GlideRecord('u_bus_service_portal_xref'); // Cross reference table for business service to portal(s)
BusXref.addQuery('u_bus_service',Scontract.getValue('u_business_service'));
BusXref.query();
while (BusXref.next()) {
var u_portal = BusXref.getDisplayValue('u_portal');
PortalX.push(BusXref.getDisplayValue('u_portal'));
}
}
var arrayUtil = new ArrayUtil();
arrayUtil.unique(PortalX);
}
Note Line 7 was moved because otherwise, you're just adding more and more query conditions to an existing GlideRecord object and will get no matches.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-09-2017 01:44 PM
Thank you Nia, that worked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2017 04:56 AM
Had the same issue, this really helped. Thanks!!