From 43c5b8f2ccdcb4396cbd58c3da83c0fe653b1585 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 12 Oct 2025 15:19:07 +0530 Subject: [PATCH 1/4] Create code.js --- .../code.js | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js diff --git a/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js new file mode 100644 index 0000000000..186e6552c9 --- /dev/null +++ b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js @@ -0,0 +1,26 @@ +(function executeRule(current, previous) { + if (!current.cmdb_ci) + return; + + var gr = new GlideAggregate('incident'); + gr.addQuery('cmdb_ci', current.cmdb_ci); + gr.addQuery('sys_created_on', '>=', gs.daysAgoStart(1)); + gr.addAggregate('COUNT'); + gr.query(); + + if (gr.next() && gr.getAggregate('COUNT') >= 5) { + var problemGR = new GlideRecord('problem'); + problemGR.addQuery('cmdb_ci', current.cmdb_ci); + problemGR.addQuery('state', '<', 8); // Not Closed + problemGR.query(); + + if (!problemGR.hasNext()) { + problemGR.initialize(); + problemGR.short_description = 'Recurring incidents on ' + current.cmdb_ci.name; + problemGR.cmdb_ci = current.cmdb_ci; + problemGR.state = 1; // New + problemGR.insert(); + gs.log('Problem created for recurring incidents on CI: ' + current.cmdb_ci.name); + } + } +})(current, previous); From 16981c7b07960b1995d2ab5233bd0df275f89347 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 12 Oct 2025 15:21:42 +0530 Subject: [PATCH 2/4] Create README.md --- .../README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md diff --git a/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md new file mode 100644 index 0000000000..9045cfc79c --- /dev/null +++ b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md @@ -0,0 +1,6 @@ +This business rule automatically creates a Problem record when there are 5 or more incidents linked to the same Configuration Item (CI) within the last 24 hours. +How it works technically: +-It first checks if the current Incident has an associated CIThen, it counts the number of incidents created in the last day for that CI. +-If the count is 5 or more, it looks for any open Problem records related to the same CI. +-If no open Problem exists, it creates a new Problem with a short description indicating recurring incidents on that CI. +-Finally, it logs the creation of the Problem. From 4b3e920939493e2fde81ca1116e692a4a41b2840 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:10:28 +0530 Subject: [PATCH 3/4] Update code.js --- .../code.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js index 186e6552c9..3c37224c9f 100644 --- a/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js +++ b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/code.js @@ -2,13 +2,13 @@ if (!current.cmdb_ci) return; - var gr = new GlideAggregate('incident'); - gr.addQuery('cmdb_ci', current.cmdb_ci); - gr.addQuery('sys_created_on', '>=', gs.daysAgoStart(1)); - gr.addAggregate('COUNT'); - gr.query(); + var ck = new GlideAggregate('incident'); + ck.addQuery('cmdb_ci', current.cmdb_ci); + ck.addQuery('sys_created_on', '>=', gs.daysAgoStart(1)); + ck.addAggregate('COUNT'); + ck.query(); - if (gr.next() && gr.getAggregate('COUNT') >= 5) { + if (ck.next() && ck.getAggregate('COUNT') >= 5) { var problemGR = new GlideRecord('problem'); problemGR.addQuery('cmdb_ci', current.cmdb_ci); problemGR.addQuery('state', '<', 8); // Not Closed From 6673e1202ac67efa5663ee3ed4f936413f68401b Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Sun, 12 Oct 2025 19:25:57 +0530 Subject: [PATCH 4/4] Update README.md --- .../README.md | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md index 9045cfc79c..b6fd630257 100644 --- a/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md +++ b/Server-Side Components/Business Rules/Auto Create Problem Records for Recurring Incidents/README.md @@ -1,6 +1,12 @@ -This business rule automatically creates a Problem record when there are 5 or more incidents linked to the same Configuration Item (CI) within the last 24 hours. -How it works technically: --It first checks if the current Incident has an associated CIThen, it counts the number of incidents created in the last day for that CI. --If the count is 5 or more, it looks for any open Problem records related to the same CI. --If no open Problem exists, it creates a new Problem with a short description indicating recurring incidents on that CI. --Finally, it logs the creation of the Problem. +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. +This helps in proactive problem management, aiming to address recurring issues. +Here’s the working of the code explained: + + - Check if CI is present in the current Incident (current.cmdb_ci). + - Count incidents created in the last 24 hours for the same CI using GlideAggregate. + +If 5 or more incidents are found for that CI: + - Query the Problem table to check if an open Problem (not closed) already exists for that CI. + - 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). + - Log a message indicating that a Problem has been created. +This automates Problem creation for frequent incidents on the same CI.