Skip to content

Commit a5c75d9

Browse files
Update README.md
1 parent a541fcc commit a5c75d9

File tree

1 file changed

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

1 file changed

+0
-52
lines changed

Core ServiceNow APIs/GlideAggregate/Find Oldest Open Incidents per Group/README.md

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,7 @@ How to use
1111
This script is intended to be used in a server-side context within a ServiceNow instance. Common use cases include:
1212
Scheduled Job: Run this script on a regular schedule (e.g., daily) to generate a report on aging incidents.
1313
Script Include: Incorporate the logic into a reusable function within a Script Include, allowing other scripts to call it.
14-
Fix Script: Execute the script as a one-off task to perform an analysis.
15-
Script
16-
javascript
17-
(function findOldestIncidents() {
18-
var ga = new GlideAggregate('incident');
19-
ga.addActiveQuery();
20-
ga.addAggregate('MIN', 'opened_at');
21-
ga.groupBy('assignment_group');
22-
ga.query();
2314

24-
while (ga.next()) {
25-
var group = ga.assignment_group.getDisplayValue();
26-
var oldestIncidentDate = ga.getAggregate('MIN', 'opened_at');
27-
gs.info("Oldest open incident for " + group + " was created on: " + oldestIncidentDate);
28-
}
29-
})();
3015
Use code with caution.
3116

3217
Installation
@@ -42,44 +27,7 @@ Navigate to System Definition > Script Includes.
4227
Click New.
4328
Name it (e.g., IncidentHelper).
4429
API Name: global.IncidentHelper
45-
Script:
46-
javascript
47-
var IncidentHelper = Class.create();
48-
IncidentHelper.prototype = {
49-
initialize: function() {
50-
},
5130

52-
findOldestIncidents: function() {
53-
var ga = new GlideAggregate('incident');
54-
ga.addActiveQuery();
55-
ga.addAggregate('MIN', 'opened_at');
56-
ga.groupBy('assignment_group');
57-
ga.query();
58-
59-
var results = [];
60-
while (ga.next()) {
61-
var group = ga.assignment_group.getDisplayValue();
62-
var oldestIncidentDate = ga.getAggregate('MIN', 'opened_at');
63-
results.push({
64-
group: group,
65-
oldestIncidentDate: oldestIncidentDate
66-
});
67-
}
68-
return results;
69-
},
70-
71-
type: 'IncidentHelper'
72-
};
73-
Use code with caution.
74-
75-
You can then call this function from other scripts. For example:
76-
javascript
77-
var helper = new IncidentHelper();
78-
var incidents = helper.findOldestIncidents();
79-
for (var i = 0; i < incidents.length; i++) {
80-
gs.info("Oldest open incident for " + incidents[i].group + " was created on: " + incidents[i].oldestIncidentDate);
81-
}
82-
Use code with caution.
8331

8432
Customization
8533
Change the output: Modify the gs.info() line to instead write to a custom log, send an email, or create a report.

0 commit comments

Comments
 (0)