Remove the inactive members
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2022 12:06 AM
In the group many of them are inactive, so two things to be done:
1. Remove the inactive members by running a fix script to fix the existing data
2. Fix the code which removes the inactive members from the group.
How to write fix script to remove the inactive members from the group.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2022 12:11 AM - edited ‎11-18-2022 12:11 AM
This code will remove inactive members from groups in fix script:
var usr = new GlideRecord('sys_user_grmember');
usr.addEncodedQuery('user.active=false');
usr.query();
while(usr.next())
{
usr.deleteRecord();
}
Raghav
MVP 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2022 12:16 AM - edited ‎11-18-2022 12:17 AM
Hi @siri27 ,
You can use below code to remove inactive user from group.
var grpMember = new GlideRecord('sys_user_grmember');
grpMember.query();
while (ggrpMember.next()) {
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery('active=false^sys_id=' +grpMember.user); //
gr.query();
if (gr.next()) {
grpMember.deleteRecord();
}
}
Please Mark My Response as Correct/Helpful based on Impact
Regards,
Gunjan Kiratkar
2X ServiceNow MVP
Community Rising Star 2022
Youtube : ServiceNow Guy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-18-2022 12:20 AM - edited ‎11-18-2022 12:21 AM
These scripts would help, however from an audit purpose, you shouldn't delete user records and it might trigger cascade deletion of the user references on the tickets. It is also a good practice for Audit purposes to keep the user and deactivate them.
Keep the user records, delete the group membership record.
Thanks & Regards,
Vikrant Sharma