- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 07:00 AM
I want to share this Glide Record with the community. I discovered this while experimenting with a Glide Record. I did not want to write multiple addorConditions so I came up with this. I have been testing arrays in Glide Records for about a month and it has always worked. My question is, how does the Glide Record loop through the array? Please feel free to try this yourself. It also works with !=, CONTAINS, DOES NOT CONTAIN .
var count = 0;
var REQs = ['5', '2', '3'];
var assnmGroup = ['Service Desk', 'Business Systems']
var gr = new GlideRecord('sc_request');
gr.addQuery('request_state', REQs);
gr.addQuery('assignment_group.name', assnmGroup);
gr.setLimit(130);
gr.query();
while (gr.next())
{
gs.log("number: " + gr.number);
gs.log("Request State: " + gr.request_state);
gs.log("Assignment Group: " + gr.assignment_group.name);
gs.log("Short Description: " + gr.short_description);
gs.log("*****************************");
count++;
}
gs.log("Count: " + count);
Snipped of the output.
*** Script: number: REQ0048208
*** Script: Request State: 3
*** Script: Assignment Group: Business Systems
*** Script: Short Description: UltiPro Time Base update
*** Script: *****************************
*** Script: number: REQ0048551
*** Script: Request State: 5
*** Script: Assignment Group: Business Systems
*** Script: Short Description: ODS Growth Curve: Add Modifiers
*** Script: *****************************
*** Script: number: REQ0048511
*** Script: Request State: 5
*** Script: Assignment Group: Business Systems
*** Script: Short Description: HS SharePoint Site
*** Script: *****************************
*** Script: number: REQ0048632
*** Script: Request State: 3
*** Script: Assignment Group: Business Systems
*** Script: Short Description: AcuTrak: DNA Sample Inv - Bulk Enter Samples - Add Current State to Results Grid
*** Script: *****************************
*** Script: number: REQ0048665
*** Script: Request State: 2
*** Script: Assignment Group: Service Desk
*** Script: Short Description: Global Protect VPN
*** Script: *****************************
*** Script: number: REQ0048660
*** Script: Request State: 5
*** Script: Assignment Group: Service Desk
*** Script: Short Description: Print from PigChamp
*** Script: *****************************
*** Script: number: REQ0028810
*** Script: Request State: 5
*** Script: Assignment Group: Service Desk
*** Script: Short Description: On-boarding Request
*** Script: *****************************
*** Script: number: REQ0048605
*** Script: Request State: 3
*** Script: Assignment Group: Service Desk
*** Script: Short Description: Quantity threshold breached: UPS Battery
*** Script: *****************************
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2020 01:23 AM
Cool, thanks for posting, i didn't know that addQuery would default to IN if you gave it an array. Please mark an answer correct to close the thread down.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 07:11 AM
Very interesting! I didn't think this would work. I assume it handles it as a "IN" query, like:
gr.addQuery("request_state", "IN", [5,2,3]);
Thanks for sharing
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 07:13 AM
Hi,
I assume it internally uses an IN operator to handle this for an array.
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 07:37 AM
See what you are saying about the "IN". But it works with gr.addQuery('request_state', '!=', REQs); So is the "!=" operator, used with the "IN" operator?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-29-2020 07:40 AM
If you add in a line like:
gs.log("query: " + gr.getEncodedQuery());
The we'll be able to see exactly what query is being submitted by that condition.