Need to close Bulk RITM's in ServiceNow state and stage as completed. Can you help me the query.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
HI Team,
i have a requirement to close Bulk RITM's in ServiceNow, state and stage as completed. Can you help me the query.
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
You can use fix script /background script to run it:
var ritmGR = new GlideRecord("sc_req_item");
ritmGR.addEncodedQuery("stateNOT IN3,4,7^<your_query_here>"); // Change <your_query_here> to filter the RITMs, like numberIN<ritmlist>
ritmGR.setLimit(100); // Batch processing
ritmGR.query();
while (ritmGR.next()) {
// Close associated tasks first
var taskGR = new GlideRecord("sc_task");
taskGR.addQuery("request_item", ritmGR.sys_id);
taskGR.addQuery("state", "NOT IN", "3,4,7");
taskGR.query();
while (taskGR.next()) {
taskGR.setValue("state", "3"); // Closed Complete
taskGR.setValue("active", false);
taskGR.update();
}
// Close the RITM
ritmGR.setValue("state", "3"); // Closed Complete
ritmGR.setValue("stage", "complete");
ritmGR.setValue("active", false);
ritmGR.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @Swathi504893573 This might help you
https://www.servicenow.com/community/developer-forum/need-help-to-close-bulk-ritms-and-sc-tasks-effi...
See an example of code to get all them:
var gr = new GlideRecord('sc_req_item');
gr.addQuery('cat_item','YOUR_CATALOG_ITEM_SYS_ID');
gr.addQuery('state','!=',3);
gr.query();
while (gr.next()) {
gr.state = 3;
gr.stage = 'completed';
gr.update();
}
