Skip to content

Commit a93e82a

Browse files
authored
Create pending Approval30days.js
script to identify and cancel RITM pending for approval for 30 days
1 parent 36780be commit a93e82a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}
39+
40+

0 commit comments

Comments
 (0)