From e066a048e58bfe7411c14ebc60b5d2580cf7ee28 Mon Sep 17 00:00:00 2001 From: Shashank_Jain Date: Sun, 12 Oct 2025 13:52:59 +0530 Subject: [PATCH 1/4] Users with no groups and roles.js --- .../Users with no groups and roles.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Orphaned Users/Users with no groups and roles.js diff --git a/Server-Side Components/Background Scripts/Orphaned Users/Users with no groups and roles.js b/Server-Side Components/Background Scripts/Orphaned Users/Users with no groups and roles.js new file mode 100644 index 0000000000..d1ea7cb0c1 --- /dev/null +++ b/Server-Side Components/Background Scripts/Orphaned Users/Users with no groups and roles.js @@ -0,0 +1,23 @@ +var userRecord = new GlideRecord('sys_user'); +userRecord.addQuery('active', true); +userRecord.query(); + +var orphanedUsers = []; + +while(userRecord.next()) { + var userSysId = userRecord.getValue('sys_id'); + + var userGroups = new GlideRecord('sys_user_grmember'); + userGroups.addQuery('user', userSysId); + userGroups.query(); + + var userRoles = new GlideRecord('sys_user_has_role'); + userRoles.addQuery('user', userSysId); + userRoles.query(); + + if(!userGroups.hasNext() && !userRoles.hasNext()) { + orphanedUsers.push(userRecord.getValue('user_name')); + } +} + +gs.print('Orphaned Users: ' + orphanedUsers.join(', ')); From 725b66910f5f45a912ab3a708aba4709fa21ebf9 Mon Sep 17 00:00:00 2001 From: Shashank_Jain Date: Sun, 12 Oct 2025 13:53:41 +0530 Subject: [PATCH 2/4] README.md --- .../Background Scripts/Orphaned Users/README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Orphaned Users/README.md diff --git a/Server-Side Components/Background Scripts/Orphaned Users/README.md b/Server-Side Components/Background Scripts/Orphaned Users/README.md new file mode 100644 index 0000000000..8b5c31c600 --- /dev/null +++ b/Server-Side Components/Background Scripts/Orphaned Users/README.md @@ -0,0 +1,4 @@ +This script identifies active users in ServiceNow who have no group memberships and no roles assigned. +It queries the sys_user table for all active users, then checks each user against the sys_user_grmember table (groups) and the sys_user_has_role table (roles). +If a user has no associated groups and no assigned roles, their username is added to a list called orphanedUsers. +Finally, the script prints the list, which can be used for user cleanup, security audits, or compliance purposes to ensure proper user management. From c4a541f0c8f5c6d41024fbfcc4cd53b315d0274c Mon Sep 17 00:00:00 2001 From: Shashank_Jain Date: Mon, 13 Oct 2025 19:00:47 +0530 Subject: [PATCH 3/4] Incident Reassignment Tracker.js --- .../Incident Reassignment Tracker.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Incident Reassignment Tracker/Incident Reassignment Tracker.js diff --git a/Server-Side Components/Background Scripts/Incident Reassignment Tracker/Incident Reassignment Tracker.js b/Server-Side Components/Background Scripts/Incident Reassignment Tracker/Incident Reassignment Tracker.js new file mode 100644 index 0000000000..724b641157 --- /dev/null +++ b/Server-Side Components/Background Scripts/Incident Reassignment Tracker/Incident Reassignment Tracker.js @@ -0,0 +1,32 @@ +(function() { + var MAX_REASSIGNMENTS = 5; + var flaggedIncidents = []; + var flaggedCount = 0; + var totalChecked = 0; + var incGR = new GlideRecord('incident'); + incGR.addActiveQuery(); + incGR.query(); + while (incGR.next()) { + totalChecked++; + // Count how many times 'assigned_to' changed + var auditAgg = new GlideAggregate('sys_audit'); + auditAgg.addQuery('documentkey', incGR.getUniqueValue()); + auditAgg.addQuery('fieldname', 'assigned_to'); + auditAgg.addAggregate('COUNT'); + auditAgg.query(); + var reassignmentCount = 0; + if (auditAgg.next()) { + reassignmentCount = parseInt(auditAgg.getAggregate('COUNT'), 10); + } + // Flag incidents exceeding threshold + if (reassignmentCount > MAX_REASSIGNMENTS) { + flaggedIncidents.push(incGR.getValue('number')); + flaggedCount++; + } + } + gs.info(' Checked: ' + totalChecked + ' | Flagged: ' + flaggedCount + ' | Threshold: ' + MAX_REASSIGNMENTS); + if (flaggedIncidents.length > 0) + gs.info(' Flagged Incidents: ' + flaggedIncidents.join(', ')); + else + gs.info(' No incidents exceeded the reassignment threshold.'); +})(); From 848dd36bece2b845c19eb45ef6d44b13365c5c19 Mon Sep 17 00:00:00 2001 From: Shashank_Jain Date: Mon, 13 Oct 2025 19:02:16 +0530 Subject: [PATCH 4/4] README.md --- .../Incident Reassignment Tracker/README.md | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Incident Reassignment Tracker/README.md diff --git a/Server-Side Components/Background Scripts/Incident Reassignment Tracker/README.md b/Server-Side Components/Background Scripts/Incident Reassignment Tracker/README.md new file mode 100644 index 0000000000..e6b25d3a63 --- /dev/null +++ b/Server-Side Components/Background Scripts/Incident Reassignment Tracker/README.md @@ -0,0 +1,9 @@ +Incident Reassignment Tracker +Use Case - +In IT service management, incidents are sometimes reassigned multiple times before reaching the right technician. +This script helps identify incidents that have been **reassigned more than 5 times**, so managers can review the assignment process and reduce ticket bouncing. + +How It Works - +1. Loops through all **active incidents**. +2. Counts how many times the **`assigned_to`** field changed using the `sys_audit` table. +3. Prints the incident numbers in the system logs if they exceed the threshold (5 reassignments by default).