Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
2da9254
script.js
trimbakeshmadhan-109 Oct 27, 2025
c9315ec
README.md
trimbakeshmadhan-109 Oct 27, 2025
5d17de8
Script.js
trimbakeshmadhan-109 Oct 27, 2025
c8c2e06
README.md
trimbakeshmadhan-109 Oct 27, 2025
14244d8
script.js
trimbakeshmadhan-109 Oct 27, 2025
45c645d
README.md
trimbakeshmadhan-109 Oct 27, 2025
3edf0bc
Update README.md
trimbakeshmadhan-109 Oct 27, 2025
fa78c36
script.js
trimbakeshmadhan-109 Oct 27, 2025
a6e23bd
README.md
trimbakeshmadhan-109 Oct 27, 2025
484bcdd
Update script.js
trimbakeshmadhan-109 Oct 27, 2025
12f9ba9
Delete Core ServiceNow APIs/GlideAggregate/Count Inactive Users with …
trimbakeshmadhan-109 Oct 28, 2025
23f8bb3
Delete Core ServiceNow APIs/GlideAggregate/Count Inactive Users with …
trimbakeshmadhan-109 Oct 28, 2025
75d8c0b
Delete Core ServiceNow APIs/GlideAggregate/Find oldest Incident based…
trimbakeshmadhan-109 Oct 28, 2025
4f13513
Delete Core ServiceNow APIs/GlideAggregate/Find oldest Incident based…
trimbakeshmadhan-109 Oct 28, 2025
5328dda
Delete Core ServiceNow APIs/GlideJsonPath/GlideJsonPath Reader Exampl…
trimbakeshmadhan-109 Oct 28, 2025
6750b61
Delete Core ServiceNow APIs/GlideJsonPath/GlideJsonPath Reader Exampl…
trimbakeshmadhan-109 Oct 28, 2025
e1e3760
script.js
trimbakeshmadhan-109 Oct 28, 2025
dcd5bd4
README.md
trimbakeshmadhan-109 Oct 28, 2025
0d23579
Delete Core ServiceNow APIs/GlideAggregate/Create Problem based on in…
trimbakeshmadhan-109 Oct 28, 2025
a541fcc
Delete Core ServiceNow APIs/GlideAggregate/Create Problem based on in…
trimbakeshmadhan-109 Oct 28, 2025
a5c75d9
Update README.md
trimbakeshmadhan-109 Oct 28, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
ServiceNow Script: Find Oldest Open Incidents per Group
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.
Overview
The script performs the following actions:
Initializes GlideAggregate: Creates an aggregate query on the incident table.
Filters Active Incidents: Uses addActiveQuery() to restrict the search to only open (active) incidents.
Aggregates by Minimum Date: Finds the minimum (MIN) opened_at date, which represents the oldest record.
Groups by Assignment Group: Groups the results by the assignment_group to get a separate result for each team.
Iterates and Logs: Loops through the query results and logs the assignment group and the opening date of its oldest open incident.
How to use
This script is intended to be used in a server-side context within a ServiceNow instance. Common use cases include:
Scheduled Job: Run this script on a regular schedule (e.g., daily) to generate a report on aging incidents.
Script Include: Incorporate the logic into a reusable function within a Script Include, allowing other scripts to call it.

Use code with caution.

Installation
As a Scheduled Job
Navigate to System Definition > Scheduled Jobs.
Click New and select Automatically run a script of your choosing.
Name the job (e.g., Find Oldest Open Incidents).
Set your desired frequency and time.
Paste the script into the Run this script field.
Save and activate the job.
As a Script Include
Navigate to System Definition > Script Includes.
Click New.
Name it (e.g., IncidentHelper).
API Name: global.IncidentHelper


Customization
Change the output: Modify the gs.info() line to instead write to a custom log, send an email, or create a report.
Refine the query: Add more addQuery() statements to filter incidents by other criteria, such as priority or category.
Change the aggregate: Use MAX instead of MIN to find the newest incident in each group.
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.
Dependencies
This script uses standard ServiceNow APIs (GlideAggregate, gs). No external libraries are required.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var ga = new GlideAggregate('incident');
ga.addActiveQuery();
ga.addAggregate('MIN', 'opened_at');
ga.groupBy('assignment_group');
ga.query();

while (ga.next()) {
var group = ga.assignment_group.getDisplayValue();
var oldestIncidentDate = ga.getAggregate('MIN', 'opened_at');
gs.info("Oldest open incident for " + group + " was created on: " + oldestIncidentDate);
}
Loading