- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 09:47 AM
Hello All,
Can please someone help me with the Fix script to close the RITM records which are active and not updated before one year ago.
i need to fetch data encoded query on RITM.
"active=true^sys_updated_on<javascript:gs.beginningOfOneYearAgo()"
I need to set the RITM state as Closed Automatically and also associated REQ and SCTASK state as Closed Automatically.
Thanks
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 09:52 AM
@Rakesh40 Please see if this script works for you.
// Define the time threshold (one year ago)
var oneYearAgo = new GlideDateTime();
oneYearAgo.addYears(-1);
// Query the RITM records that are active and not updated for over a year
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('active', true);
ritmGr.addQuery('sys_updated_on', '<', oneYearAgo);
ritmGr.query();
while (ritmGr.next()) {
// Close the RITM record
ritmGr.state = 'closed_complete'; // or the appropriate closed state value
ritmGr.update();
// Get associated REQUEST record and close it
var requestGr = new GlideRecord('sc_request');
if (requestGr.get(ritmGr.request)) {
requestGr.state = 'closed_complete'; // or the appropriate closed state value
requestGr.update();
}
// Close associated SCTASK records
var sctaskGr = new GlideRecord('sc_task');
sctaskGr.addQuery('request_item', ritmGr.sys_id);
sctaskGr.addQuery('state', '!=', 'closed_complete'); // Only update tasks that are not already closed
sctaskGr.query();
while (sctaskGr.next()) {
sctaskGr.state = 'closed_complete'; // or the appropriate closed state value
sctaskGr.update();
}
}
gs.info('RITMs, Requests, and SCTasks have been closed successfully.');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 09:52 AM
@Rakesh40 Please see if this script works for you.
// Define the time threshold (one year ago)
var oneYearAgo = new GlideDateTime();
oneYearAgo.addYears(-1);
// Query the RITM records that are active and not updated for over a year
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery('active', true);
ritmGr.addQuery('sys_updated_on', '<', oneYearAgo);
ritmGr.query();
while (ritmGr.next()) {
// Close the RITM record
ritmGr.state = 'closed_complete'; // or the appropriate closed state value
ritmGr.update();
// Get associated REQUEST record and close it
var requestGr = new GlideRecord('sc_request');
if (requestGr.get(ritmGr.request)) {
requestGr.state = 'closed_complete'; // or the appropriate closed state value
requestGr.update();
}
// Close associated SCTASK records
var sctaskGr = new GlideRecord('sc_task');
sctaskGr.addQuery('request_item', ritmGr.sys_id);
sctaskGr.addQuery('state', '!=', 'closed_complete'); // Only update tasks that are not already closed
sctaskGr.query();
while (sctaskGr.next()) {
sctaskGr.state = 'closed_complete'; // or the appropriate closed state value
sctaskGr.update();
}
}
gs.info('RITMs, Requests, and SCTasks have been closed successfully.');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-02-2024 09:20 AM
@Rakesh40 Please mark this an accepted solution if it managed to address your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-14-2024 05:24 AM
Hi Sandeep, can you help in resolving the issue I have.
Even though I close all the SCTASKS under the RITM, the RITM is not closed complete automatically.
I somehow got this script but it is also not helping