Skip to content

Commit d9aafaa

Browse files
authored
Merge pull request #2453 from d-sharmagit/schedulejob-approval30days
Schedulejob approval30days
2 parents 36780be + 14025bf commit d9aafaa

File tree

2 files changed

+46
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)