Notification from Incident Table, when all incident tasks are closed

Kendra F
Tera Contributor

My goal is to send an Notification from the Incident Table when All Incident Tasks are closed. The Notification and Event are on the Incident Table and the Business Rule is on the Incident_Task table. I also need to include all task numbers under the Incident within the notification. 

 

I have written an Event to trigger when any Incident Task is closed. Then the Business Rule (Script below) which calls the Notification.  

 

var count = 0;
var gr = new GlideAggregate('incident_task');
gr.addQuery('incident', current.incident);
gr.addEncodedQuery('stateNOT IN3,7,4')
//.addQuery('state', '!=', 3);

gr.addAggregate('COUNT');
gr.query();
if (gr.next()) {
    count = gr.getAggregate('COUNT');
}
if (count >= 1) {
    next;
} else {
         gs.eventQueue('incident.incident_tasks.closed', current, current.sys_id, current.assigned_to);
 
What I get now is the notification firing after each Incident Task is completed.
 
What am I missing?
9 REPLIES 9

Medi C
Giga Sage

Hi @Kendra F,

 

Are all incident tasks created when the incident is created? Or they are created at later stages or manuall? 

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Kendra F
Tera Contributor

They are created later manually.

@Kendra F

You can use the following script (Script 1). However, there could be a use case when you have for example 2 incident tasks, when both would be closed, then the notification would be sent out. Later if you create an additional Incident Task, and it gets closed, this would trigger another notification.

 

What would be the best, if you have a defined number of incident task which gets created within incident lifecycle you can try script 2. and adjust the number of incident tasks

 

SCRIPT 1:
var count = 0;
var gr = new GlideAggregate('incident_task');
gr.addEncodedQuery("incident=" + current.incident + "^active=true")
gr.addAggregate('COUNT');
gr.query();
if (gr.next()) {
    count = parseInt(gr.getAggregate('COUNT'));
}
if (count == 0) {
    gs.eventQueue('incident.incident_tasks.closed', current, current.sys_id, current.assigned_to);
} 

 

 

 

SCRIPT 2:
var count = 0;
var gr = new GlideAggregate('incident_task');
gr.addEncodedQuery("incident=" + current.incident + "^active=false")
gr.addAggregate('COUNT');
gr.query();
if (gr.next()) {
    count = parseInt(gr.getAggregate('COUNT'));
}
if (count == 4) { //Replace 4 with the defined number of incident tasks
    gs.eventQueue('incident.incident_tasks.closed', current, current.sys_id, current.assigned_to);
} 

 

 


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Kendra F
Tera Contributor

Thanks for helping! Still having issues.

I used #1 example above, then I created Incident with two Incident Tasks.  Closed one Task and it produced two notifications even though there is one task still open. I had tried something very similar to what you suggested before and couldn't get it to work.

 

Also, how would i list the numbers of the Tasks associated on the Incident?