when problem ticket closed then related incidents close automatically

divya123
Giga Contributor

when problem ticket closed then related incidents tickets should close automatically, i write below code but that is not working, kindly help me with your suggestions. (function executeRule(current, previous /*null when async*/) { var gr =new GlideRecord('incident'); gr.addQuery('problem_id',current.sys_id); gr.query(); if(gr.next()){ gr.state= '6'; gr.close_code= Solved('Work Around'); gr.close_notes= resolved; gr.update(); } })(current, previous); Thanks

1 ACCEPTED SOLUTION

amlanpal
Kilo Sage

Hi Divya,



You need to create/modify a after Update Business rule in the Problem ('problem') table with the Conditions and script as per below screenshot. I have tested the code and is working in my instance. Would like to request you to give it a try and let me know.


For your simplicity, I'm providing the code here:



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



      var gr = new GlideRecord('incident');


      gr.addActiveQuery(); //Cross check only active incidents


      gr.addQuery('problem_id', current.sys_id);


      gr.query();


      while(gr.next()){


              gr.state = '6';


              gr.close_code = 'Solved (Work Around)';


              gr.close_notes = 'The incident is Resolved as the Related Problem is Closed/Resolved';


              gr.update();


      }


      gs.addInfoMessage('The Incident'+ gr.number+' is Resolved');



})(current, previous);



find_real_file.png


find_real_file.png



I hope this helps.Please mark correct/helpful based on impact


View solution in original post

7 REPLIES 7

amlanpal
Kilo Sage

Hi Divya,



You need to create/modify a after Update Business rule in the Problem ('problem') table with the Conditions and script as per below screenshot. I have tested the code and is working in my instance. Would like to request you to give it a try and let me know.


For your simplicity, I'm providing the code here:



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



      var gr = new GlideRecord('incident');


      gr.addActiveQuery(); //Cross check only active incidents


      gr.addQuery('problem_id', current.sys_id);


      gr.query();


      while(gr.next()){


              gr.state = '6';


              gr.close_code = 'Solved (Work Around)';


              gr.close_notes = 'The incident is Resolved as the Related Problem is Closed/Resolved';


              gr.update();


      }


      gs.addInfoMessage('The Incident'+ gr.number+' is Resolved');



})(current, previous);



find_real_file.png


find_real_file.png



I hope this helps.Please mark correct/helpful based on impact


Thank you Amlan Pal for your response.


Hi Amlan,



Your script works well.....thank you for sharing it.   However it appears to be closing all incidents, not just the parent.   How can it be tweaked so only the parent Incident is closed?


Never mind I figured it out.   Needed to replace.....



gr.addQuery('problem_id',current.sys_id);



with....



gr.addQuery('sys_id',current.parent);