- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 07:02 AM
Hello All,
The are multiple RITMs which is in open state even when the related catalog tasks is closed,
Could you please help with a BG/fix script to update all the RITM state to closed whose catalog tasks are closed
Please note : we have to only update those RITMs with state (open/pending/inprogress) but has related catalog tasks in Closed state.
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 07:16 AM - edited 07-20-2023 07:27 AM
Hello @Kaustubh k ,
Refer below script, update values accordingly
// Script for multiple records closure
var ritmGR = new GlideRecord('sc_req_item'); // table name
ritmGR.addEncodedQuery("stateIN-5,1,2"); // filtered query
ritmGR.query();
while (ritmGR.next()) {
// Query for related Catalog Tasks in the "Closed" state
var relatedCatalogTasks = new GlideRecord('sc_task');
relatedCatalogTasks.addQuery('request_item', ritmGR.sys_id);
relatedCatalogTasks.addQuery('state', '3'); // closed complete
relatedCatalogTasks.query();
// If no Catalog Tasks found in "Closed" state, exit the script
if (!relatedCatalogTasks.hasNext()) {
return;
}
// update RITM as closed complete
else {
ritmGR.setValue('state', '3'); // closed complete
ritmGR.setWorkflow(false);
ritmGR.update();
gs.info("Record Updated " + ritmGR.number);
}
}
Note : You can use count while checking task if Count of all attached task is equal to count of closed task then update RITM as closed complete
Kindly mark correct and helpful if applicable

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-20-2023 07:16 AM - edited 07-20-2023 07:27 AM
Hello @Kaustubh k ,
Refer below script, update values accordingly
// Script for multiple records closure
var ritmGR = new GlideRecord('sc_req_item'); // table name
ritmGR.addEncodedQuery("stateIN-5,1,2"); // filtered query
ritmGR.query();
while (ritmGR.next()) {
// Query for related Catalog Tasks in the "Closed" state
var relatedCatalogTasks = new GlideRecord('sc_task');
relatedCatalogTasks.addQuery('request_item', ritmGR.sys_id);
relatedCatalogTasks.addQuery('state', '3'); // closed complete
relatedCatalogTasks.query();
// If no Catalog Tasks found in "Closed" state, exit the script
if (!relatedCatalogTasks.hasNext()) {
return;
}
// update RITM as closed complete
else {
ritmGR.setValue('state', '3'); // closed complete
ritmGR.setWorkflow(false);
ritmGR.update();
gs.info("Record Updated " + ritmGR.number);
}
}
Note : You can use count while checking task if Count of all attached task is equal to count of closed task then update RITM as closed complete
Kindly mark correct and helpful if applicable