Skip to content

Commit 0011511

Browse files
authored
Remove inactive user from active groups (#1094)
* Create Remove Inactive user from active group.js This code snippet helps to remove the inactive users from active groups. * Create README.md
1 parent c322fdc commit 0011511

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
var user = new GlideRecord("sys_user");
2+
user.addInactiveQuery(); // Filter the InActive user from the sys_user table.
3+
user.query();
4+
while(user.next()){
5+
var group = new GlideRecord("sys_user_group");
6+
group.addQuery("user",user.getUniqueValue()); // Compare the group in which Inactive user would find.
7+
group.query();
8+
if(group.next()){
9+
// gs.print("Group sys_id is "+ group.getUniqueValue());
10+
var groupMember= new GlideRecord("sys_user_grmember");
11+
groupMember.addQuery("group",group.getUniqueValue()); // Compare the group member in which Inactive user would find.
12+
groupMember.query();
13+
if(groupMember.next()){
14+
gs.print("Group sys_id is "+ group.getUniqueValue()); // Get the sys_id of the group;
15+
gs.print("Member sys_id is "+ groupMember.getUniqueValue()); // Get the sys_id of the member which is inactive.
16+
gs.print("Deleted record is "+ groupMember.sys_id); // Get the sys_id of the record which is going to delete;
17+
groupMember.deleteRecord(); // Delete the record
18+
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)