File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed
Server-Side Components/Scheduled Jobs/CancelApproval Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ Scheduled Script Execution: Auto-cancel RITM if group manager approval pending after 30 days
2+
3+ This script:
4+ - Finds RITM records older than 30 days
5+ - Checks if any group manager approvals are still pending (state='requested')
6+ - If so, cancels the RITM (sets state to 'Cancelled')
7+ Usage:
8+ - Schedule this script to run daily.
Original file line number Diff line number Diff line change 1+ /*
2+ Scheduled Script Execution: Auto-cancel RITM if group manager approval pending after 30 days
3+
4+ This script:
5+ - Finds RITM records older than 30 days
6+ - Checks if any group manager approvals are still pending (state='requested')
7+ - If so, cancels the RITM (sets state to 'Cancelled')
8+ Usage:
9+ - Schedule this script to run daily.
10+ */
11+
12+ // Calculate date 30 days ago
13+ var thirtyDaysAgo = new GlideDateTime ( ) ;
14+ thirtyDaysAgo . addDaysUTC ( - 30 ) ;
15+
16+ // Query RITMs older than 30 days and not closed/cancelled already
17+ var ritmGR = new GlideRecord ( 'sc_req_item' ) ;
18+ ritmGR . addQuery ( 'sys_created_on' , '<=' , thirtyDaysAgo ) ;
19+ ritmGR . addEncodedQuery ( 'stateIN1,2,112^cat_item=a24b1e113bc21e1050109c9c24e45a51' ) ;
20+ ritmGR . query ( ) ;
21+
22+ while ( ritmGR . next ( ) ) {
23+ // Query approvals for this RITM from group managers - adjust condition accordingly
24+ var approvalGR = new GlideRecord ( 'sysapproval_approver' ) ;
25+ approvalGR . addQuery ( 'sysapproval' , ritmGR . sys_id ) ; // approvals linked to this RITM
26+ approvalGR . addQuery ( 'state' , 'requested' ) ; // pending approvals
27+ approvalGR . query ( ) ;
28+
29+ if ( approvalGR . hasNext ( ) ) {
30+ // Group manager approvals pending after 30 days => Cancel RITM
31+
32+ ritmGR . state = 8 ; // Closed Cancelled
33+ ritmGR . assignment_group = '<assignment_group_name or sysid>' ; //group ABC
34+ ritmGR . work_notes = 'Auto-cancelled due to no group manager approval within 30 days.' ;
35+ ritmGR . update ( ) ;
36+
37+ }
38+ }
You can’t perform that action at this time.
0 commit comments