File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
Server-Side Components/Business Rules/Auto-approved opened by is approver Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 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 ) ;
You can’t perform that action at this time.
0 commit comments