Skip to content

Commit badabe4

Browse files
authored
Improve incident handling (#1515)
* script.js * readme.md * script.js
1 parent 1f1b703 commit badabe4

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Suppose you want to gather data about incident resolution in your system.
2+
Specifically, you need to find the total number of incidents, the average time to resolution (in hours), and the number of incidents per assignment group.
3+
This information can help analyze the efficiency of different groups and improve incident handling.
4+
5+
Below are the added Aggregations:
6+
7+
inc.addAggregate('COUNT') gets the total count of resolved incidents.
8+
inc.addAggregate('AVG', 'calendar_duration') calculates the average calendar duration for incident resolution (measured in hours).
9+
inc.addAggregate('COUNT', 'assignment_group') counts incidents per assignment group, and ga.groupBy('assignment_group') groups the result by assignment group to produce totals per group.
10+
11+
Result:
12+
- It fetches total counts, average resolution time, and group-specific counts.
13+
- Logs the total number of resolved incidents and the average resolution time.
14+
- For each assignment group, it logs the group’s sys_id and the corresponding incident count.
15+
16+
Benefits of Using GlideAggregate:
17+
- Reduces the number of queries and records you need to process, as it performs calculations at the database level.
18+
- Works well with large datasets, making it suitable for summary reports and dashboards.
19+
- Allows grouping and multiple aggregations (e.g., AVG, COUNT, MIN, MAX) on various fields in a single query.
20+
21+
This GlideAggregate example provides a consolidated view of incident resolution statistics, which can aid in optimizing group efficiency and improving response times.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Create a GlideAggregate instance for the Incident table
2+
var inc = new GlideAggregate('incident');
3+
4+
// Filter for resolved incidents only
5+
inc.addQuery('state', 6);
6+
7+
// Add aggregations
8+
inc.addAggregate('COUNT'); // Total number of incidents
9+
inc.addAggregate('AVG', 'calendar_duration'); // Average resolution time in hours
10+
inc.addAggregate('COUNT', 'assignment_group'); // Count of incidents per assignment group
11+
inc.groupBy('assignment_group'); // Group by assignment group to get the count per group
12+
inc.query();
13+
14+
var totalIncidents = 0;
15+
var averageResolution = 0;
16+
var results = [];
17+
18+
while (inc.next()) {
19+
totalIncidents = inc.getAggregate('COUNT');
20+
averageResolution = inc.getAggregate('AVG', 'calendar_duration');
21+
22+
// Get assignment group and incident count per group
23+
var groupSysId = inc.assignment_group.toString();
24+
var groupIncidentCount = inc.getAggregate('COUNT', 'assignment_group');
25+
26+
results.push({
27+
groupSysId: groupSysId,
28+
groupIncidentCount: groupIncidentCount
29+
});
30+
}
31+
32+
// Display results in logs
33+
gs.info("Total Resolved Incidents are: " + totalIncidents);
34+
gs.info("Average Resolution Time (hours) is: " + averageResolution);
35+
36+
results.forEach(function(result) {
37+
gs.info("Assignment Group: " + result.groupSysId + " | Incident Count: " + result.groupIncidentCount);
38+
});

0 commit comments

Comments
 (0)