Skip to content

Commit 6e4da1e

Browse files
Find Oldest Open Incidents per Group - Pull4 (#2559)
* script.js Automatically create a problem record from incident volume Use case: Automatically create a problem record if a specific Configuration Item (CI) is associated with more than a certain number of incidents within a defined timeframe. Code snippet This code can be placed in a Scheduled Script Execution or an After Insert Business Rule to check new incidents * README.md * Script.js Identify the oldest active incident for each assignment group. This helps managers focus on long-running tickets that may require special attention. * README.md * script.js This example searches a JSON document for all developers listed under the specified path. * README.md * Update README.md * script.js Identify inactive users who still have unresolved incidents. This helps with offboarding processes and ensures incidents aren't left unattended. * README.md * Update script.js * Delete Core ServiceNow APIs/GlideAggregate/Count Inactive Users with Active incidents/README.md * Delete Core ServiceNow APIs/GlideAggregate/Count Inactive Users with Active incidents/script.js * Delete Core ServiceNow APIs/GlideAggregate/Find oldest Incident based Assignment Groups/README.md * Delete Core ServiceNow APIs/GlideAggregate/Find oldest Incident based Assignment Groups/script.js * Delete Core ServiceNow APIs/GlideJsonPath/GlideJsonPath Reader Example/README.md * Delete Core ServiceNow APIs/GlideJsonPath/GlideJsonPath Reader Example/script.js * script.js Find Oldest Open Incidents per Group * README.md * Delete Core ServiceNow APIs/GlideAggregate/Create Problem based on incident volume/README.md * Delete Core ServiceNow APIs/GlideAggregate/Create Problem based on incident volume/script.js * Update README.md
1 parent fc46b6a commit 6e4da1e

File tree

2 files changed

+49
-0
lines changed
  • Core ServiceNow APIs/GlideAggregate/Find Oldest Open Incidents per Group

2 files changed

+49
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
ServiceNow Script: Find Oldest Open Incidents per Group
2+
This script leverages GlideAggregate to efficiently find the oldest active incident for each assignment group. This is a powerful tool for monitoring and reporting on potential service level agreement (SLA) risks and improving incident management processes.
3+
Overview
4+
The script performs the following actions:
5+
Initializes GlideAggregate: Creates an aggregate query on the incident table.
6+
Filters Active Incidents: Uses addActiveQuery() to restrict the search to only open (active) incidents.
7+
Aggregates by Minimum Date: Finds the minimum (MIN) opened_at date, which represents the oldest record.
8+
Groups by Assignment Group: Groups the results by the assignment_group to get a separate result for each team.
9+
Iterates and Logs: Loops through the query results and logs the assignment group and the opening date of its oldest open incident.
10+
How to use
11+
This script is intended to be used in a server-side context within a ServiceNow instance. Common use cases include:
12+
Scheduled Job: Run this script on a regular schedule (e.g., daily) to generate a report on aging incidents.
13+
Script Include: Incorporate the logic into a reusable function within a Script Include, allowing other scripts to call it.
14+
15+
Use code with caution.
16+
17+
Installation
18+
As a Scheduled Job
19+
Navigate to System Definition > Scheduled Jobs.
20+
Click New and select Automatically run a script of your choosing.
21+
Name the job (e.g., Find Oldest Open Incidents).
22+
Set your desired frequency and time.
23+
Paste the script into the Run this script field.
24+
Save and activate the job.
25+
As a Script Include
26+
Navigate to System Definition > Script Includes.
27+
Click New.
28+
Name it (e.g., IncidentHelper).
29+
API Name: global.IncidentHelper
30+
31+
32+
Customization
33+
Change the output: Modify the gs.info() line to instead write to a custom log, send an email, or create a report.
34+
Refine the query: Add more addQuery() statements to filter incidents by other criteria, such as priority or category.
35+
Change the aggregate: Use MAX instead of MIN to find the newest incident in each group.
36+
Get incident details: To get the actual incident record (e.g., its number), you would need to perform a secondary GlideRecord query based on the aggregated data.
37+
Dependencies
38+
This script uses standard ServiceNow APIs (GlideAggregate, gs). No external libraries are required.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
var ga = new GlideAggregate('incident');
2+
ga.addActiveQuery();
3+
ga.addAggregate('MIN', 'opened_at');
4+
ga.groupBy('assignment_group');
5+
ga.query();
6+
7+
while (ga.next()) {
8+
var group = ga.assignment_group.getDisplayValue();
9+
var oldestIncidentDate = ga.getAggregate('MIN', 'opened_at');
10+
gs.info("Oldest open incident for " + group + " was created on: " + oldestIncidentDate);
11+
}

0 commit comments

Comments
 (0)