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

Yousaf
Giga Sage

Hi MR,


Please Change this > gr.addQuery('change_request.sys_id', current.sys_id);

with this > gr.addQuery('change_request', current.getUniqueValue());

and try 

Mark Correct or Helpful if it helps.

Thanks,

Yousaf


***Mark Correct or Helpful if it helps.***

MR1
Tera Contributor

Thanks for your response!

I already tried that but it didn't work 

https://community.servicenow.com/community?id=community_question&sys_id=5307943fdb0e4810d82ffb2439961949

 

Maik Skoddow
Tera Patron
Tera Patron

Hi

I'm wondering why you want to create a new BR as OOTB there is already a BR "Cancel change_tasks" on table "change_request" which does the job for you.

Kind regards
Maik

MR1
Tera Contributor

Thanks for your response!

would you mind sharing the script over here. Because I didn't find any OOB script with that name "Cancel change_tasks" .