Skip to content

Commit 216ca01

Browse files
script.js
1 parent 4a9be5b commit 216ca01

File tree

1 file changed

+32
-0
lines changed
  • Server-Side Components/Server Side/Count Inactive Users with Active incidents

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)