diff --git a/Background Scripts/Remove Inactive User/README.md b/Background Scripts/Remove Inactive User/README.md new file mode 100644 index 0000000000..4e71c10715 --- /dev/null +++ b/Background Scripts/Remove Inactive User/README.md @@ -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. diff --git a/Background Scripts/Remove Inactive User/Remove Inactive user from active group.js b/Background Scripts/Remove Inactive User/Remove Inactive user from active group.js new file mode 100644 index 0000000000..02bd66d1d4 --- /dev/null +++ b/Background Scripts/Remove Inactive User/Remove Inactive user from active group.js @@ -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 + + } +} +}