Auto Close subsequent Change Tasks when one change task is cancelled

simonberger
Kilo Contributor

Hi, I'm struggling to compile a Business Rule script for a scenario I need. When I have multiple change tasks, if I close/cancel one of them I need to then auto close all of the others within the change request as well, with a specific reason code that is showing in a drop down list of a custom field.

So for example, I have 4 change tasks called:

Implement change

Inform CAB

Restrict capabilities

Control output

If within the 'Implement Change' task I close or cancel it, it should auto close the other three and select a closure code from a drop down field list that Ive created as a custom field.

I know how to auto close tasks if the change request is cancelled using a BR with a glide record and referring to the state record reference, so I presume its something similar?

I'd like to know how to set this please...

1 ACCEPTED SOLUTION

EashVerma
Giga Expert

Hello Simon,



To work on this, please write a Business Rule with Before and Update checked, select the advanced option and give condition in when to Run as " State changes to Closed" or as per the requirement.



In the advanced tab, write the following code:



(function executeRule(current, previous /*null when async*/) {




// Add your code here




var gr = new GlideRecord('change_request');


gr.addQuery('number',current.change_request);


gr.query();


while(gr.next()){


gr.setValue('state',3); //3 is the state for closed in my instance


gr.update();


}



var gs = new GlideRecord('change_task');


gs.addQuery('change_request',current.change_request);


gs.query();


while(gs.next()){


gs.setValue('state',3); //3 is the state for closed in my instance


gs.update();


}



})(current, previous);




It should work, if not, please let me know.


View solution in original post

7 REPLIES 7

Sorry I don't understand how or where the closure type of 'Cancelled by Implement Task' would be factored into that section of the script?


EashVerma
Giga Expert

Basically, I have used state as your u_closure_type and 4 is the state for Cancelled by Implement Task.


OK yes that has worked. Thank you