close multiple catalog tasks when ritm is closed..

latha13
Tera Contributor

HI,

I want to set state as closed complete for all catalog tasks when ritm state is closed complete..This is happens for only 1 catalog item only..

Here i wrote brule on requested item

after ,update

when to run:state changes to closed complete and Item is .....

var reqItem= new GlideRecord('sc_task');
reqItem.addQuery('request_item',current.sys_id);
reqItem.query();
 while(reqItem.next()){

reqItem.setValue('state',3);
 reqItem.update();
 }

Here when i close ritm state only 1 catalog task is closed, after closing 1st task 2nd is opened but not closed it  is in open state....how to achieve?

Thanks in advance...

11 REPLIES 11

Hi,

what it means only 2 tasks closed complete

How many tasks are created for this RITM?

if 3 then you want only 2 tasks to closed?

could you be more clear and precise.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

hi,

In workflow i used 2 tasks so i want to close 2 only...

Hi,

So this script should close tasks belonging to the RITM

Is it closing any other unwanted tasks?

please check how many tasks for current RITM?

var reqItem= new GlideRecord('sc_task');
reqItem.addQuery('request_item',current.sys_id);
reqItem.query();
 while(reqItem.next()){

reqItem.setValue('state',3);
 reqItem.update();
 }

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hope you are doing good.

Did my reply answer your question?

If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.

Thanks!
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,

I created a BR on sc_req_item table and the above code has helped me.

When I close RITM all the attached CAtalog Tasks are closed as well.

Thanks for your help.

Manthan