Auto-Close Incident when Incident Tasks are Closed

bvarian
Mega Contributor

I have some Incidents (INC) that contain Incident Tasks (TASK) and would like the Incident to auto-resolve when all Incident Tasks are closed to prevent anyone from having to manually resolve the Incident ticket itself (all actionable items are contained on the tasks...this parent/child is just a grouping construct).

 

I created an "after" Business Rule, but it's not working and I haven't been able to figure out why.  We require close code/close notes so at first I thought an absence of those in my BR script might be the reason, but even after adding those, I'm not getting the change.  I've also tried the state as both '6' and 'Resolved'.

 

If anyone might have suggestions, I'd be very appreciative.  Thanks!

 

find_real_file.png

 

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

var gr = new GlideRecord('incident_task');

gr.addQuery('incident', current.incident);

gr.addQuery('active', true);

gr.addQuery('sys_id', '!=', current.sys_id);

gr.query();

var count = gr.getRowCount();

if(count == 0)

{

var gr1 = new GlideRecord('incident');

gr1.addQuery('sys_id', current.incident);

gr1.query();

if(gr1.next())

{

gr1.state = '6';
gr1.close_code = 'Solved (Permanently)';
gr1.close_notes = "Auto-Closed based on Incident Tasks being Closed";

gr1.update();

}

}

})(current, previous);