- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2016 08:07 AM
I have a situation where I need to query our groups via GlideRecord and I need to check if "type" is either null or does not contain one of the types. I've tried a few different ways of doing this, but either don't return the null types, return all groups, or don't get any groups. This is the current script (returns nothing because of the addnullquery):
//Check group membership
var m = new GlideRecord('sys_user_grmember');
m.addQuery('user',current.sys_id);
m.query();
var groupList = [];
while(m.next()){
groupList.push(m.group + '');
}
groupList = new ArrayUtil().unique(groupList);
var gm = new GlideRecord('sys_user_group');
gm.addQuery('sys_id','IN',groupList);
gm.addQuery('type','DOES NOT CONTAIN','64d411974f082240709af7e18110c76c');
var gm2 = gm.addNullQuery('type');
gm2.orderBy('name');
gm2.query();
while(gm2.next()){
gs.info('2MonitorInactiveUsers Group' + gm2.name + 'Member');
addToDescription('Group',gm2.name,'Member');
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2016 08:11 AM
Instead this section,
gm.addQuery('sys_id','IN',groupList);
gm.addQuery('type','DOES NOT CONTAIN','64d411974f082240709af7e18110c76c');
var gm2 = gm.addNullQuery('type');
Form the query on UI by changing the filter condition. Right click on the filter and copy query.
Later use the copied query in a addEncodedQuery.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2016 08:11 AM
Instead this section,
gm.addQuery('sys_id','IN',groupList);
gm.addQuery('type','DOES NOT CONTAIN','64d411974f082240709af7e18110c76c');
var gm2 = gm.addNullQuery('type');
Form the query on UI by changing the filter condition. Right click on the filter and copy query.
Later use the copied query in a addEncodedQuery.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2016
08:20 AM
- last edited on
‎07-28-2024
10:13 PM
by
David
Hi Kristen,
To supplement what Kalai said - If you want a walk-thru video demo
Video: Scripting Complex Queries Quickly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-10-2016 11:14 AM
Thanks Kalai and Chuck! That helped and it's working now.