Skip to content

Commit 036d425

Browse files
authored
Auto Create Problem Records for Recurring Incidents (#2053)
* Create code.js * Create README.md * Update code.js * Update README.md
1 parent d17e4ba commit 036d425

File tree

2 files changed

+38
-0
lines changed
  • Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents

2 files changed

+38
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
This "after" business rule automatically creates a Problem record when a particular Configuration Item (CI) has had 5 or more incidents in the last 24 hours, and no open Problem already exists for that CI.
2+
This helps in proactive problem management, aiming to address recurring issues.
3+
Here’s the working of the code explained:
4+
5+
- Check if CI is present in the current Incident (current.cmdb_ci).
6+
- Count incidents created in the last 24 hours for the same CI using GlideAggregate.
7+
8+
If 5 or more incidents are found for that CI:
9+
- Query the Problem table to check if an open Problem (not closed) already exists for that CI.
10+
- If no open Problem exists, create a new Problem record with: The same CI, A predefined short description And set its state to New (1).
11+
- Log a message indicating that a Problem has been created.
12+
This automates Problem creation for frequent incidents on the same CI.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
(function executeRule(current, previous) {
2+
if (!current.cmdb_ci)
3+
return;
4+
5+
var ck = new GlideAggregate('incident');
6+
ck.addQuery('cmdb_ci', current.cmdb_ci);
7+
ck.addQuery('sys_created_on', '>=', gs.daysAgoStart(1));
8+
ck.addAggregate('COUNT');
9+
ck.query();
10+
11+
if (ck.next() && ck.getAggregate('COUNT') >= 5) {
12+
var problemGR = new GlideRecord('problem');
13+
problemGR.addQuery('cmdb_ci', current.cmdb_ci);
14+
problemGR.addQuery('state', '<', 8); // Not Closed
15+
problemGR.query();
16+
17+
if (!problemGR.hasNext()) {
18+
problemGR.initialize();
19+
problemGR.short_description = 'Recurring incidents on ' + current.cmdb_ci.name;
20+
problemGR.cmdb_ci = current.cmdb_ci;
21+
problemGR.state = 1; // New
22+
problemGR.insert();
23+
gs.log('Problem created for recurring incidents on CI: ' + current.cmdb_ci.name);
24+
}
25+
}
26+
})(current, previous);

0 commit comments

Comments
 (0)