- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 02:48 AM
How to write a script in ServiceNow to get all the Active groups with Inactive members.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 02:58 AM
Hello Bhagya,
You can use below script to find the active groups with Inactive users information.
var grSUG = new GlideRecord('sys_user_grmember');
grSUG.addEncodedQuery("group.active=true^user.active=false"); //Filter condition
grSUG.query();
while (grSUG.next()) {
gs.info('group: ' + grSUG.getValue('group'));
gs.info('user: ' + grSUG.getValue('user'));
}
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
Regards
Sulabh Garg

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-24-2022 02:58 AM
Hello Bhagya,
You can use below script to find the active groups with Inactive users information.
var grSUG = new GlideRecord('sys_user_grmember');
grSUG.addEncodedQuery("group.active=true^user.active=false"); //Filter condition
grSUG.query();
while (grSUG.next()) {
gs.info('group: ' + grSUG.getValue('group'));
gs.info('user: ' + grSUG.getValue('user'));
}
Please Mark ✅ Correct/helpful, if applicable, Thanks!!
Regards
Sulabh Garg
Regards
Sulabh Garg
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 09:59 PM
In this same script if I want only group names which starts with G_IT then how can i get that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-08-2022 10:06 PM
Hi,
Try below code
var grSUG = new GlideRecord('sys_user_grmember');
grSUG.addEncodedQuery("group.active=true^user.active=false^groupSTARTSWITHG_IT"); //Filter condition
grSUG.query();
while (grSUG.next()) {
gs.info('group: '+grSUG.getDisplayValue('group'));
gs.info('group: ' + grSUG.getValue('group'));
gs.info('user: ' + grSUG.getValue('user'));
}
Please mark my response as correct or helpful if applicable