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);

1 ACCEPTED SOLUTION

Prateek kumar
Mega Sage

Can we try something like this.

(function executeRule(current, previous /*null when async*/) {
var count=0;
var tasks = new GlideRecord('incident_task');
tasks.addQuery('parent',current.parent);
tasks.query();
var taskcount = tasks.getRowCount();
while(tasks.next())
{		
if(tasks.state == 3 ||tasks.state == 4 || tasks.state == 7)//change as required
{
count++;
}
}
if(count == taskcount)
{
var inc = new GlideRecord('incident');
inc.addQuery('sys_id',current.parent);
inc.query();
if(inc.next())
{
inc.state = 6;
	inc.update();
	}

}

})(current, previous);

Please mark my response as correct and helpful if it helped solved your question.
-Thanks

View solution in original post

15 REPLIES 15

Awesome! Glad you got a solution that worked for you. If you don't mind, please mark the correct answer as correct as that helps others find it faster, but you can also mark other posts as Helpful, if they were.

Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!