From 5ebf488a085b6274db4d084b580639cd20ed3b21 Mon Sep 17 00:00:00 2001 From: Abhishek Thakur <146176327+at8807602@users.noreply.github.com> Date: Wed, 2 Oct 2024 04:46:36 -0700 Subject: [PATCH 1/2] Create Remove Inactive user from active group.js This code snippet helps to remove the inactive users from active groups. --- .../Remove Inactive user from active group.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Background Scripts/Remove Inactive User/Remove Inactive user from active group.js 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 + + } +} +} From 33399896b8096f43ae27588f698fe79b59f34a3d Mon Sep 17 00:00:00 2001 From: Abhishek Thakur <146176327+at8807602@users.noreply.github.com> Date: Wed, 2 Oct 2024 04:48:34 -0700 Subject: [PATCH 2/2] Create README.md --- Background Scripts/Remove Inactive User/README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Background Scripts/Remove Inactive User/README.md 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.