|
| 1 | +Count Active Incidents Assigned to Inactive Users This script uses GlideAggregate to efficiently count the number of active incidents assigned to inactive users. |
| 2 | + |
| 3 | +This is a crucial task for maintaining data hygiene and preventing incidents from being stalled due to inactive assignees. |
| 4 | + |
| 5 | +Overview The script performs the following actions: Initializes GlideAggregate: Creates an aggregate query on the incident table. |
| 6 | + |
| 7 | +Filters Records: Uses addQuery() to restrict the search to incidents that are both active (true) and assigned to a user whose active status is false. |
| 8 | + |
| 9 | +This filter uses a "dot-walk" on the assigned_to field to check the user's active status directly within the query. |
| 10 | + |
| 11 | +Aggregates by Count: Uses addAggregate() to count the number of incidents, grouping the results by assigned_to user. |
| 12 | + |
| 13 | +Executes and Logs: Runs the query, then loops through the results. |
| 14 | + |
| 15 | +For each inactive user found, it logs their name and the number of active incidents assigned to them. Use case This script is essential for regular cleanup and maintenance. |
| 16 | + |
| 17 | +It can be used in: Scheduled Job: Automatically run the script daily or weekly to monitor for and report on incidents assigned to inactive users. Fix Script: Perform a one-off run to identify and log all current incidents that need reassignment. Reporting: The output from this script can be used to build a report for managers to track and reassign incidents promptly. Script javascript var ga = new GlideAggregate('incident'); ga.addQuery('active', true); ga.addQuery('assigned_to.active', false); ga.addAggregate('COUNT', 'assigned_to'); ga.query(); |
| 18 | + |
| 19 | +while (ga.next()) { var inactiveUser = ga.assigned_to.getDisplayValue(); var taskCount = ga.getAggregate('COUNT', 'assigned_to'); gs.info("Inactive user " + inactiveUser + " has " + taskCount + " active incidents."); } Use code with caution. |
| 20 | + |
| 21 | +Installation As a Scheduled Job Navigate to System Definition > Scheduled Jobs. |
| 22 | + |
| 23 | + |
| 24 | +Click New and select Automatically run a script of your choosing. Name the job (e.g., Find Incidents Assigned to Inactive Users). |
| 25 | + |
| 26 | + |
| 27 | +Set your desired frequency and time. Paste the script into the Run this script field. Save and activate the job. As a Fix Script Navigate to System Definition > Fix Scripts. |
| 28 | + |
| 29 | +Click New. Name it (e.g., Find Active Incidents with Inactive Assignee). |
| 30 | + |
| 31 | + |
| 32 | +Paste the script into the Script field. Run the script to see the results in the System Log. |
| 33 | + |
| 34 | + |
| 35 | +Customization Targeted tables: Change the table name from incident to task or any other table with an assigned_to field to check for active records assigned to inactive users. |
| 36 | + |
| 37 | + |
| 38 | +Automated reassignment: Extend the script to automatically reassign the incidents to a group or another user. This is a common practice to ensure that tickets do not get stuck in the queue. Email notification: Instead of logging the information, modify the script to send an email notification to the group manager or another stakeholder with the list of incidents needing attention. |
0 commit comments