- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2021 03:58 AM
HI All,
We had an issue with few of the RITMs, where RITMs with multiple tasks are not closed even if all their associated catalog tasks are closed. The requirment is to identify all those RITMs by getting them into log and close them.
Note: All those RITMs have multiple tasks each.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2021 04:57 AM
Run this code in a fix script. Mark as helpful if it helped.
var ritm = new GlideRecord("sc_req_item");
//check for all active RITM
ritm.addEncodedQuery("active=true");
ritm.query();
while (ritm.next()) {
var task_incomplete = 0;
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item', ritm.sys_id);
tasks.query();
while (tasks.next()) {
//check is task is ative
if (tasks.active == true) {
task_incomplete = 1;
}
}
//close RITM if all tasks are inactive
if (task_incomplete == 0) {
//close all RITM with no active Tasks
ritm.setValue('active', false);
ritm.update();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2021 05:00 AM
For this you can write a after business rule on update of sc_task table
If task gets completed, it should check state of all sister tasks (All child tasks of the parent).
If all are in completed state, mark RITM complete.
Otherwise Scheduled Jobs to check it everyday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2021 06:09 AM
Hi,
please update script as this
var ritm = new GlideRecord("sc_req_item");
ritm.addActiveQuery();
ritm.query();
while (ritm.next()) {
var tasks = new GlideRecord('sc_task');
tasks.addActiveQuery();
tasks.addQuery('request_item', ritm.sys_id);
tasks.setLimit(1);
tasks.query();
if(!tasks.next()) {
ritm.setValue('active', false);
ritm.state = 3;
ritm.update();
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 04:08 AM
I've seen this several times lately, and most of them have the same root cause:
You need to ensure you set the stage to "complete" in a flow, or workflow at the end of the process.
For Flow Designer, that is update the triggering record, to stage: complete. For a workflow, that is setting the stage of the workflow.
I had to run a fix script similar to the above.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 08:52 PM
thanks , are there any steps available which i can use to fix this ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-01-2022 04:15 AM
Which part are you trying to fix?
For existing records, if you open sc_req_item and create a view that shows you all of the records in question (ie: finished, but not "closed complete") you can copy that encoded query into an .addEncodedQuery() statement, then set them to stage = complete (I think that's 3, if I recall correctly, but could be wrong here.. look at the choice list for stage.)
For fixing the root cause, if it is due to incorrect staging, either add the stage "complete" to the end step of your workflow, or use a flow to set the RITM record to stage = complete.