From 823cc2bd9764f477e786cf4b054d562ec3cb233b Mon Sep 17 00:00:00 2001 From: chaytarak <62869669+chaytarak@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:44:16 +0530 Subject: [PATCH 1/2] ReadMe.md --- .../ReadMe.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Server-Side Components/Business Rules/Auto-approved opened by is approver/ReadMe.md diff --git a/Server-Side Components/Business Rules/Auto-approved opened by is approver/ReadMe.md b/Server-Side Components/Business Rules/Auto-approved opened by is approver/ReadMe.md new file mode 100644 index 0000000000..bb65031acd --- /dev/null +++ b/Server-Side Components/Business Rules/Auto-approved opened by is approver/ReadMe.md @@ -0,0 +1,17 @@ +>**When a new Approval record (sysapproval_approver table) is created** + +1. Create a Before Business Rule on the Approval (sysapproval_approver) table. + +2. Check if the table of the record being approved is the Requested For table. + +3. If it does: + + Verify whether the Approver (approver) is the same as the Opened by (opened_by) field on the related Requested For record. + + If both match: + + Automatically approve the approval record. + + Add appropriate approval comments (e.g., “Auto-approved since approver is the requestor (Opened By).”) + + Use setWorkflow(false) to prevent triggering additional workflows or business rules. From bca57e78deec05d083cf761d203a5ef0bbc200d7 Mon Sep 17 00:00:00 2001 From: chaytarak <62869669+chaytarak@users.noreply.github.com> Date: Tue, 28 Oct 2025 16:45:21 +0530 Subject: [PATCH 2/2] Code.js --- .../code.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Server-Side Components/Business Rules/Auto-approved opened by is approver/code.js diff --git a/Server-Side Components/Business Rules/Auto-approved opened by is approver/code.js b/Server-Side Components/Business Rules/Auto-approved opened by is approver/code.js new file mode 100644 index 0000000000..6545c0b1dc --- /dev/null +++ b/Server-Side Components/Business Rules/Auto-approved opened by is approver/code.js @@ -0,0 +1,37 @@ +(function executeRule(current, previous /*null when async*/ ) { + + try { + gs.setWorkflow(false); + if (!current.sysapproval) + return; + + // Get the parent record (RITM / REQ / etc.) + var parent = current.sysapproval.getRefRecord(); + if (!parent || !parent.isValidRecord()) + return; + + if (parent.getTableName() == "sc_req_item") { + + // Load Opened By user record + var userGR = new GlideRecord("sys_user"); + if (!userGR.get(parent.requested_for)) + return; + + + // If approver == Opened By → auto-approve + if (current.approver == parent.opened_by) { + current.state = "approved"; + current.comments = "Auto-approved as " + current.getDisplayValue("approver") + " is the manager of Requested For"; + current.update(); + + // Also update parent RITM stage to 'Approved' + parent.stage = "approved"; + parent.update(); + } + } + + } catch (ex) { + gs.error("Auto-approval BR error: " + ex.message); + } + +})(current, previous);