Cancel the change task on cancellation of change request

MR1
Tera Contributor

Hi All,

I need help to cancel the change task on cancellation of change request. Currently, I am using the below script and it is cancelling the change task only when change task assigned to is NOT Empty. If assigned to on change task remains empty then it do not cancel it.

This BR is on After on changer request table and condition is "active changes to false".

var gr = new GlideRecord('change_task');
gr.addQuery('active', true);
gr.addQuery('change_request.sys_id', current.sys_id);
// I tried this line also  gr.addQuery('change_request', current.sys_id);  --- didn't help
gr.query();
while(gr.next())
{
gr.state=7; // cancel value
gr.active=false;
gr.update();
gs.addInfoMessage('test2');
}

Thanks

5 REPLIES 5

Sagar Pagar
Tera Patron

Hi,

As @Maik Skoddow suggested, yes there is OOTB After business rule on change request [change_request] table with name - Cancel change_tasks

 

URL - https://instance_name.service-now.com/sys_script.do?sys_id=16bd8e77c34332001488b731c1d3aeeb&sysparm_record_target=sys_script&sysparm_record_row=1&sysparm_record_rows=1&sysparm_record_list=nameSTARTSWITHCancel+change_tasks%5EORDERBYDESCsys_updated_on

 

Thanks,
Sagar Pagar

The world works with ServiceNow