File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Core ServiceNow APIs/GlideAggregate/Count Inactive Users with Active incidents Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ This script uses GlideAggregate to find the number of active incidents
3+ that are assigned to users who are currently marked as inactive.
4+ GlideAggregate is used instead of a standard GlideRecord query
5+ because it is more efficient for performing calculations like COUNT
6+ directly in the database.
7+ */
8+ var ga = new GlideAggregate ( 'incident' ) ;
9+
10+ // Query for active incidents.
11+ ga . addQuery ( 'active' , true ) ;
12+
13+ // Use dot-walking to query for incidents assigned to inactive users.
14+ ga . addQuery ( 'assigned_to.active' , false ) ;
15+
16+ // Add an aggregate function to count the incidents, grouped by the assigned user.
17+ ga . addAggregate ( 'COUNT' , 'assigned_to' ) ;
18+
19+ // Execute the query.
20+ ga . query ( ) ;
21+
22+ // Process the results of the aggregate query.
23+ while ( ga . next ( ) ) {
24+ // Get the display name of the inactive user from the current record.
25+ var inactiveUser = ga . assigned_to . getDisplayValue ( ) ;
26+
27+ // Get the count of active incidents for this specific user.
28+ var incidentCount = ga . getAggregate ( 'COUNT' , 'assigned_to' ) ;
29+
30+ // Log the result to the system logs.
31+ gs . info ( "Inactive user " + inactiveUser + " has " + incidentCount + " active incidents." ) ;
32+ }
You can’t perform that action at this time.
0 commit comments