From 47e57b4b6c65d5d68da9ce624373ae8ea0c46e3b Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:40:52 +0530 Subject: [PATCH 1/2] Create code.js --- .../code.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/code.js diff --git a/Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/code.js b/Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/code.js new file mode 100644 index 0000000000..91caa0a044 --- /dev/null +++ b/Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/code.js @@ -0,0 +1,19 @@ +(function executeRule(current, previous /*null when async*/) { + + var wasClosed = previous.state == 7; // Closed + var isNowActive = current.state != 7; + + var closureTime = new GlideDateTime(previous.sys_updated_on); + var now = new GlideDateTime(); + var minutesSinceClosure = GlideDateTime.subtract(now, closureTime).getNumericValue() / (1000 * 60); + + if (wasClosed && isNowActive && minutesSinceClosure < 5) { + gs.eventQueue('incident.reopened_quickly', current, current.assigned_to, gs.getUserID()); + + current.work_notes = 'Reopened automatically — user reopened within 5 minutes of closure.'; + + // Optionally flag the incident + current.u_reopened_flag = true; + } + +})(current, previous); From b659260740ed0fdacbe98cce1d6c4d76046fa4c8 Mon Sep 17 00:00:00 2001 From: Chetna Sharma <146471211+chetnadev@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:43:07 +0530 Subject: [PATCH 2/2] Create README.md --- .../README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/README.md diff --git a/Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/README.md b/Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/README.md new file mode 100644 index 0000000000..acb92453a7 --- /dev/null +++ b/Server-Side Components/Business Rules/Automatically Reopen Incidents Closed Prematurely/README.md @@ -0,0 +1,6 @@ +If a user reopens a closed incident within 5 minutes of closure (e.g., because the issue wasn't actually resolved), automatically reopen it, log the reason, and notify the assigned user. +This code detects when an incident is reopened within 5 minutes of being closed. It compares the previous and current state of the record, and if it was previously Closed (state = 7) and is now Active, it calculates the time since closure. If the reopening happened within 5 minutes, it: +Triggers an event incident.reopened_quickly for notifications or logging. +Adds a work note explaining the automatic flag. +Sets a custom flag field u_reopened_flag to true for tracking. +This is useful for identifying and tracking incidents that are quickly reopened, possibly indicating incomplete resolution.