Close RITM when catalog task is closed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 03:31 PM - edited 12-06-2022 03:37 PM
Hello Experts,
we have RITM that will have one or multiple tasks. I need to set RITM to cancelled when all catalog tasks are cancelled but set RITM to closed complete if atleast one catalog task is set to closed complete because not all tasks are cancelled. How can I achieve that. ?
Thanks,
Rocky.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 02:32 PM
Hi @Rocky5 ,
You can use below code should be run on sc_task table on before update
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();
}
}
For more information follow this link and I have provided code from given link
I hope this helps to understand the logic.
Please mark my answer correct if this helps you
Thanks
Mohit

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 05:36 AM
Can you please elaborate your requirement ? it is not clear ?
Regards,
Musab
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-07-2022 04:12 PM
Hi Musab,
The requirement is when we submit catalog item three sctasks are created, And fulfillers with cancel or close those sctasks. So, after all tasks are closed or canceled (I.e. tasks are inactive) after last is updated I need to check if atleast one sctask is closed complete the RITM should be closed.
If all sctasks are cancelled, RITM should be canceled.
if all sctasks are closed complete, RITM should be closed complete.
Thanks,
Rocky.