From 89cec720db8d08d8faa8a0e39ed05fe201915c76 Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Fri, 3 Oct 2025 17:51:37 +0530 Subject: [PATCH 1/2] Create scriptBR.js --- .../scriptBR.js | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/scriptBR.js diff --git a/Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/scriptBR.js b/Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/scriptBR.js new file mode 100644 index 0000000000..e6f6118d4a --- /dev/null +++ b/Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/scriptBR.js @@ -0,0 +1,21 @@ +(function executeRule(current, previous /*null when async*/ ) { + + // Query for any child incidents related to the current parent incident. + var childIncidents = new GlideRecord('incident'); + childIncidents.addQuery('parent_incident', current.sys_id); + childIncidents.addEncodedQuery('state!=6^ORstate!=7^ORstate!=8'); // state is not closed,Resoved,cancelled + childIncidents.addActiveQuery(); + childIncidents.query(); + // Check if any open child incidents were found. + if (childIncidents.getRowCount() > 0) { + var childNumbers = []; + while (childIncidents.next()) { + childNumbers.push(childIncidents.number.toString()); + } + // Display an error message with the open child incident numbers. + gs.addErrorMessage('Cannot close this incident. Please close the following child incidents first: ' + childNumbers.join(', ')); + //prevent saving the record + current.setAbortAction(true); + } + +})(current, previous); From d13be201702a94dcae1dbe1f2eb2a64dccee97f6 Mon Sep 17 00:00:00 2001 From: Naveen Kumar <103413520+naveensnow@users.noreply.github.com> Date: Fri, 3 Oct 2025 17:55:58 +0530 Subject: [PATCH 2/2] Create README.md --- .../README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/README.md diff --git a/Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/README.md b/Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/README.md new file mode 100644 index 0000000000..33ac8238f1 --- /dev/null +++ b/Server-Side Components/Business Rules/Abort Parent Incident Closure When Child is Open/README.md @@ -0,0 +1,16 @@ +This business rule is designed for ServiceNow to prevent a parent incident from being closed or resolved while it still has active child incidents. +If a user attempts to set the parent incident's state to "Resolved," "Closed," or "Cancelled," the rule will query for any related child incidents that are still open. +If open children are found, the update will be aborted, and an error message will be displayed to the user. + +Navigate to System Definition > Business Rules in the ServiceNow filter navigator. +Click New. +Fill out the form with the following details: +Name: Prevent Parent Closure with Open Children +Table: Incident [incident] +Advanced: true +When: before +Update: Check this box. +In the When to run tab, set the Condition field: +current.state.changesTo(7) || current.state.changesTo(6) || current.state.changesTo(8) +Note: The state values (6, 7, 8) may vary based on your instance configuration. +In the Advanced tab, paste the provided script into the Script field.