Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
and the script is:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
yesterday
Hi @swatis22 ,
You can use a Wait for Condition activity to ensure all associated Catalog Tasks are closed before the workflow proceeds to close the RITM.
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('active', true); // Checks for any task that is still active (state is 1, 2, or 3)
taskGR.query();
answer = !taskGR.hasNext(); // Returns true only when NO active tasks remainPlacing this logic in a Wait for Condition activity will cause the workflow to pause and re-evaluate whenever a related Catalog Task is updated. The workflow will continue only after all Catalog Tasks for the RITM are no longer active.
Also, verify that there are no custom Business Rules, Flows, or Script Actions on sc_task or sc_req_item that are closing the RITM when the first task is completed.
You can also refer to this ServiceNow Community thread which discusses the same requirement:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hi @swatis22
- Drag the 3 separate Catalog Task activities out of your workflow so they run in parallel/ connect them sequentially with a Join at the end.
- Connect the Wait or Always condition of all three Catalog Tasks to a single Join activity.
- Connect the output of the Join activity to your "Set Values" or "End" activity.
Result: The workflow will pause at the Join until all three tasks output their condition before proceeding to close the RITM
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
my suggestion
-> don't close RITM from your workflow
-> use after update BR on catalog task table and then close RITM once last catalog task is closed
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 as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader