From dea384799ab65216b37c90610baf29580d842082 Mon Sep 17 00:00:00 2001 From: Sai Charan Koratala Date: Mon, 13 Oct 2025 23:19:16 +0530 Subject: [PATCH 1/2] Update Auto_Deactivate_Users_Not_Logged_In_for_X_Days.js updating the existing code to remove the dormant user from enrolled groups --- ...activate_Users_Not_Logged_In_for_X_Days.js | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/Auto_Deactivate_Users_Not_Logged_In_for_X_Days.js b/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/Auto_Deactivate_Users_Not_Logged_In_for_X_Days.js index 5f0c36300f..a3a949cd68 100644 --- a/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/Auto_Deactivate_Users_Not_Logged_In_for_X_Days.js +++ b/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/Auto_Deactivate_Users_Not_Logged_In_for_X_Days.js @@ -23,12 +23,32 @@ function deactivateDormantUsers(daysInactive) { var count = 0; while (gr.next()) { gr.active = false; + removeUserFromGroups(gr.sys_id.toString()); //calling the function to remove the user from enrolled groups gr.update(); count++; } gs.info('✅ Deactivated ' + count + ' users inactive for over ' + daysInactive + ' days (before ' + cutoff.getDisplayValue() + ').'); } +// below function is used to remove the user from the groups which the user is already a part of +function removeUserFromGroups(userSysId) { + var gm = new GlideRecord('sys_user_grmember'); + gm.addQuery('user', userSysId); + gm.query(); + + var removedCount = 0; + while (gm.next()) { + var groupName = gm.group.name.toString(); + gm.deleteRecord(); + removedCount++; + gs.info('Removed from group: ' + groupName); + } + + if (removedCount === 0) + gs.info('No group memberships found for user: ' + userSysId); + else + gs.info('Removed ' + removedCount + ' group memberships for user: ' + userSysId); +} // Example run // deactivateDormantUsers(90); From 16d1587af5f5c4ba5a76b51b7f3c7f0da50291ba Mon Sep 17 00:00:00 2001 From: Sai Charan Koratala Date: Mon, 13 Oct 2025 23:23:41 +0530 Subject: [PATCH 2/2] Update README.md updated the file with latest comments related to the new function --- .../Auto-Deactivate Users Not Logged In for X Days/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/README.md b/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/README.md index 8d987462ea..0e88a796a6 100644 --- a/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/README.md +++ b/Server-Side Components/Background Scripts/Auto-Deactivate Users Not Logged In for X Days/README.md @@ -7,3 +7,6 @@ 2. Paste the script and execute: ```javascript deactivateDormantUsers(90); + +**Script Explanation** + This script helps the admin team to identify the users who are inactive since the last "x" amount of days and make their profiles inactive. Along with the deactivation of user accounts, the group memberships of the user profiles also will be removed to prevent any mishappen.