Close RITM when catalog task is closed

Rocky5
Kilo Sage

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.

7 REPLIES 7

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

Musab Rasheed
Tera Sage
Tera Sage

Can you please elaborate your requirement ? it is not clear ?

Please hit like and mark my response as correct if that helps
Regards,
Musab

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.