From e06a954b8500ddd083a09bb19eedbaa33a65f31a Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:44:52 +0530 Subject: [PATCH 1/3] script.js --- .../script.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/script.js diff --git a/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/script.js b/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/script.js new file mode 100644 index 0000000000..1fab41772f --- /dev/null +++ b/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/script.js @@ -0,0 +1,29 @@ +(function() { + var parentSysId = 'a83820b58f723300e7e16c7827bdeed2'; // Replace with actual parent incident sys_id + var childIncidents = new GlideRecord('incident'); + childIncidents.addQuery('parent_incident', parentSysId); + childIncidents.query(); + var allClosed = true; + while (childIncidents.next()) { + if (childIncidents.state != 7) { // 7 = Closed + allClosed = false; + gs.info("Child incident " + childIncidents.number + " is still open."); + } + } + if (allClosed) { + var parent = new GlideRecord('incident'); + if (parent.get(parentSysId)) { + parent.state = 7; // Closed + parent.close_code = 'Duplicate'; // Adjust to valid closure code in your instance + parent.close_notes = 'Automatically closed since all child incidents are closed.'; + parent.setWorkflow(false); // Prevent triggering BRs/workflows + parent.update(); + + gs.info("Parent incident [" + parent.number + "] has been closed automatically."); + } else { + gs.warn("Parent incident not found for sys_id: " + parentSysId); + } + } else { + gs.info("Parent not closed because one or more child incidents are still open."); + } +})(); From 864efa2c99b691815e2fd07465222966fbdfa27d Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:46:46 +0530 Subject: [PATCH 2/3] README.md --- .../README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md diff --git a/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md b/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md new file mode 100644 index 0000000000..8a2c4a69dc --- /dev/null +++ b/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md @@ -0,0 +1 @@ +This background script allows administrators to close a parent incident automatically if all its child incidents are already closed. From db4e2e5f131117c879bf359d82ece85e9d2c41ec Mon Sep 17 00:00:00 2001 From: Code with bhav <92107107+bhavyaa30@users.noreply.github.com> Date: Fri, 3 Oct 2025 16:48:13 +0530 Subject: [PATCH 3/3] README.md --- .../README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md b/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md index 8a2c4a69dc..0f3adf1591 100644 --- a/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md +++ b/Server-Side Components/Background Scripts/Update Parent Incident State To Closed If All Child Incident Is Closed/README.md @@ -1 +1,4 @@ -This background script allows administrators to close a parent incident automatically if all its child incidents are already closed. +This Background Script provides administrators with a quick and reliable method to: ++Check whether all child incidents under a parent are closed. ++Automatically close the parent if all children are resolved. ++Ensure consistent closure logic without manual intervention.