Write a script to delete all the inactive users who are the member of network group.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2024 01:24 PM
2 REPLIES 2

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2024 02:05 PM
This is a script I generated from chatgpt. You can make changes to it and use it as required.
// Define the group name
var groupName = 'network';
// Query the sys_user_group table to get the group details
var groupGr = new GlideRecord('sys_user_group');
groupGr.addQuery('name', groupName);
groupGr.query();
if (groupGr.next()) {
// Get the group ID
var groupId = groupGr.getUniqueValue();
// Query the sys_user_grmember table to get the inactive users who are members of the group
var memberGr = new GlideRecord('sys_user_grmember');
memberGr.addQuery('group', groupId);
memberGr.addQuery('user.active', false); // Filter inactive users
memberGr.query();
// Delete the inactive users from the group
while (memberGr.next()) {
memberGr.deleteRecord();
}
gs.info("Inactive users who were members of the '" + groupName + "' group have been deleted.");
} else {
gs.error("Group '" + groupName + "' not found.");
}
Please mark this response as correct or helpful if it assisted you with your question.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-10-2024 02:34 PM
Hi, unfortunately your requirement is not clear in your post, are you removing the users from their membership of the 'network' group? or deleting the sys_user records of users who are a member of the group but are inactive?
Note: normally it is not recommended that you delete reference data like sys_user records.