Skip to content

Commit 3b64682

Browse files
Create Problem based on incident volume - pull 1 (#2557)
* 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
1 parent be8de35 commit 3b64682

File tree

2 files changed

+50
-0
lines changed
  • Core ServiceNow APIs/GlideAggregate/Create Problem based on incident volume

2 files changed

+50
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Key features
2+
Automatic problem creation: The script uses a GlideAggregate query to count the number of incidents opened for a specific CI.
3+
Time-based threshold: Problems are only created if more than five incidents are opened within a 60-minute window.
4+
Targeted incidents: The script focuses on incidents related to the same CI, making it effective for identifying recurring infrastructure issues.
5+
Customizable conditions: The number of incidents and the time frame are easily configurable within the script.
6+
Efficient performance: The use of GlideAggregate ensures the database is queried efficiently, minimizing performance impact.
7+
8+
How it works
9+
The script is designed to be executed as a server-side script, typically within a Business Rule. When an incident is inserted or updated, the script performs the following actions:
10+
Queries incidents: It executes a GlideAggregate query on the incident table.
11+
Sets conditions: The query is filtered to count all incidents that meet the following conditions:
12+
Same CI: The incident's cmdb_ci matches the cmdb_ci of the current record.
13+
Within the last hour: The opened_at time is within the last 60 minutes.
14+
Evaluates count: After the query is run, the script checks if the count of matching incidents exceeds the threshold (in this case, 5).
15+
Creates problem: If the threshold is exceeded, a new problem record is initialized.
16+
The short_description is automatically populated with a descriptive message.
17+
The cmdb_ci is linked to the new problem record.
18+
The new record is then inserted into the database.
19+
Implementation steps
20+
Create a Business Rule:
21+
Navigate to System Definition > Business Rules.
22+
Click New.
23+
Configure the Business Rule:
24+
Name: Auto Create Problem from Multiple Incidents
25+
Table: Incident [incident]
26+
Advanced: true
27+
When to run: Select after and check the Insert and Update checkboxes. This ensures the script runs after an incident has been saved.
28+
Filter conditions: Optionally, you can add conditions to limit when the script runs (e.g., cmdb_ci is not empty).
29+
Add the script:
30+
Navigate to the Advanced tab.
31+
Copy and paste the script into the Script field.
32+
Customize (optional):
33+
Number of incidents: Change the > 5 value to adjust the threshold.
34+
Time frame: Adjust the gs.minutesAgoStart(60) value to change the time window.
35+
Other conditions: If you need to check for specific incident statuses or categories, add more addQuery lines to the GlideAggregate call.
36+
Save the Business Rule.
37+
Customization examples
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var incidentCheck = new GlideAggregate('incident');
2+
incidentCheck.addQuery('cmdb_ci', current.cmdb_ci); // Or any specific CI
3+
incidentCheck.addQuery('opened_at', '>', 'javascript:gs.minutesAgoStart(60)');
4+
incidentCheck.addAggregate('COUNT');
5+
incidentCheck.query();
6+
7+
if (incidentCheck.next() && parseInt(incidentCheck.getAggregate('COUNT')) > 5) {
8+
var problem = new GlideRecord('problem');
9+
problem.initialize();
10+
problem.short_description = 'Multiple incidents reported for CI: ' + current.cmdb_ci.getDisplayValue();
11+
problem.cmdb_ci = current.cmdb_ci;
12+
problem.insert();
13+
}

0 commit comments

Comments
 (0)