Skip to content

Remove inactive user from active groups #1094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Background Scripts/Remove Inactive User/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This code snippet helps to remove the inactive users from active groups. It won't delete the user record from "sys_user" table it will just delete the entry from the "sys_user_grmember" table.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var user = new GlideRecord("sys_user");
user.addInactiveQuery(); // Filter the InActive user from the sys_user table.
user.query();
while(user.next()){
var group = new GlideRecord("sys_user_group");
group.addQuery("user",user.getUniqueValue()); // Compare the group in which Inactive user would find.
group.query();
if(group.next()){
// gs.print("Group sys_id is "+ group.getUniqueValue());
var groupMember= new GlideRecord("sys_user_grmember");
groupMember.addQuery("group",group.getUniqueValue()); // Compare the group member in which Inactive user would find.
groupMember.query();
if(groupMember.next()){
gs.print("Group sys_id is "+ group.getUniqueValue()); // Get the sys_id of the group;
gs.print("Member sys_id is "+ groupMember.getUniqueValue()); // Get the sys_id of the member which is inactive.
gs.print("Deleted record is "+ groupMember.sys_id); // Get the sys_id of the record which is going to delete;
groupMember.deleteRecord(); // Delete the record

}
}
}
Loading