Using Arrays in Glide Records

stevethomas
Giga Contributor

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: *****************************
1 ACCEPTED SOLUTION

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.

View solution in original post

11 REPLIES 11

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.

BabyYoda
Tera Expert

Is this documented anywhere? I don't see it spelled out in ServiceNow's Reference API anywhere. Is this an undocumented feature then? As such, it's possible it could break in the future if ServiceNow isn't officially supporting it. I think that's important to note here, so your code doesn't break in a future upgrade for a feature that was either unintentionally implemented by ServiceNow or the intent was there but it's never been documented and, thus, it could be removed intentionally or otherwise at a future date. Just a word to the wise, as I was puzzled by this, too, analyzing some ServiceNow Partner code and noticed GlideRecord took the query passing in an Array object as a param and without the need to specify "IN".