close the task when ritm is closed
						
					
					
				
			
		
	
			
	
	
	
	
	
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
02-12-2025 12:33 AM
Hi , i have been trying to close the parent ritm when all the childs are closed.
here is the before update BR with condition state changed to closed complete
var count=0;
var tasks = new GlideRecord('sc_task');
tasks.addQuery('request_item',current.request_item);
tasks.query();
var taskcount = tasks.getRowCount();
while(tasks.next())
{
if(tasks.state == 3)
{
count++
}
}
if(count == taskcount)
{
var rq = new GlideRecord('sc_req_item');
rq.addQuery('sys_id',current.request_item);
rq.query();
if(rq.next())
{
rq.state = 3;
rq.update();
}
} 
but its not working as expected as when state changed to WIP then its moving to close complete state in RITM
do advise as what is wrong.
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
02-12-2025 05:03 AM
If I am not wrong it is OOTB, when task get closed the RITM get close via flow only.
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.
Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]
****************************************************************************************************************
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
02-12-2025 05:38 AM
you can use business rule or flow designer for this
BR approach: I shared the script few years ago; check this
How can we close RITM when all the catalog task is closed for that item?
you can use after update BR on sc_task
Condition: State [IS ONE OF] Closed Complete/Closed Incomplete AND Request Item.Item == Your Catalog Item
Script:
(function executeRule(current, previous /*null when async*/) {
        // Add your code here
        var gr = new GlideRecord('sc_task');
        gr.addQuery('request_item', current.request_item);
        gr.addQuery('active', true);
        gr.query();
        if(!gr.next()){
               var ritm = current.request_item.getRefRecord();
               ritm.state = 3;
               ritm.update();
        }
})(current, previous);
Flow Designer approach: I shared solution few years ago
I have shared solution below using flow designer to close parent INC when all child INCs are closed.
Enhance it for sc_req_item and sc_task table
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
 - Bookmark
 - Subscribe
 - Mute
 - Subscribe to RSS Feed
 - Permalink
 - Report Inappropriate Content
 
04-01-2025 08:18 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
