From a8f07958e55fe0f6eb645295419f292018815220 Mon Sep 17 00:00:00 2001 From: chaitanyalal18 <42643661+chaitanyalal18@users.noreply.github.com> Date: Mon, 20 Oct 2025 18:46:32 +0530 Subject: [PATCH 1/2] Create README.md Updating script use cases --- .../Prevent Creation of Recursive BR/README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Server-Side Components/Business Rules/Prevent Creation of Recursive BR/README.md diff --git a/Server-Side Components/Business Rules/Prevent Creation of Recursive BR/README.md b/Server-Side Components/Business Rules/Prevent Creation of Recursive BR/README.md new file mode 100644 index 0000000000..2621a9cf60 --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Creation of Recursive BR/README.md @@ -0,0 +1,11 @@ +Using current.update() in Business rule is not recommended from servicenow due to following reasons- +1. Before- Records will be saved automatically after BR executes so using current.update is redundant +2. After- Triggers all "before" BRs again causing recursion calls and performance issue +3. Async- Same issue as in After +4. Query- current object doesn't exist and will cause error +5. Display- Runs before UI is rendered. Using current.update doesn't make sense. + +To avoid such scenarios, a business rule can be configured on the 'sys_script' table will trigger an error message and +block the creation of any new business rule if it detects the use of current.update() within the script. + +Runs: onBefore insert. From 6ee6effa42d605cc322ab1c6559da729afd8a54b Mon Sep 17 00:00:00 2001 From: chaitanyalal18 <42643661+chaitanyalal18@users.noreply.github.com> Date: Mon, 20 Oct 2025 18:54:24 +0530 Subject: [PATCH 2/2] Create script.js script update --- .../Prevent Creation of Recursive BR/script.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Server-Side Components/Business Rules/Prevent Creation of Recursive BR/script.js diff --git a/Server-Side Components/Business Rules/Prevent Creation of Recursive BR/script.js b/Server-Side Components/Business Rules/Prevent Creation of Recursive BR/script.js new file mode 100644 index 0000000000..a62c1a970a --- /dev/null +++ b/Server-Side Components/Business Rules/Prevent Creation of Recursive BR/script.js @@ -0,0 +1,12 @@ +(function executeRule(current, previous /*null when async*/) { + // Check if the script contains 'current.update()' + if (current.script && current.script.toLowerCase().includes('current.update()')) { + var errMsg = "Error: 'current.update()' should not be used in Business Rules."; + + // Abort the insert/update operation + gs.addErrorMessage(errMsg); + current.setAbortAction(true); + } + + +})(current, previous);