Skip to content

Commit bca57e7

Browse files
authored
Code.js
1 parent 823cc2b commit bca57e7

File tree

1 file changed

+37
-0
lines changed
  • Server-Side Components/Business Rules/Auto-approved opened by is approver

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(function executeRule(current, previous /*null when async*/ ) {
2+
3+
try {
4+
gs.setWorkflow(false);
5+
if (!current.sysapproval)
6+
return;
7+
8+
// Get the parent record (RITM / REQ / etc.)
9+
var parent = current.sysapproval.getRefRecord();
10+
if (!parent || !parent.isValidRecord())
11+
return;
12+
13+
if (parent.getTableName() == "sc_req_item") {
14+
15+
// Load Opened By user record
16+
var userGR = new GlideRecord("sys_user");
17+
if (!userGR.get(parent.requested_for))
18+
return;
19+
20+
21+
// If approver == Opened By → auto-approve
22+
if (current.approver == parent.opened_by) {
23+
current.state = "approved";
24+
current.comments = "Auto-approved as " + current.getDisplayValue("approver") + " is the manager of Requested For";
25+
current.update();
26+
27+
// Also update parent RITM stage to 'Approved'
28+
parent.stage = "approved";
29+
parent.update();
30+
}
31+
}
32+
33+
} catch (ex) {
34+
gs.error("Auto-approval BR error: " + ex.message);
35+
}
36+
37+
})(current, previous);

0 commit comments

Comments
 (0)