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

Could you please share screenshots from your Notification? When to send section.

Is it Send When "Event is fired"? and your event is mapped in there correctly?


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

Here you go, thanks.

 

Notification - What.PNG

notification - when.PNG

  

Thanks a lot for your quick revert. Let's give it a try with the following approach.

  1. Deactivate your business rule
  2. Adjust the notification condition as highlighted below:
    MediC_1-1741390560582.png

     

  3. In the Advanced Condition, please provide the following script:

 

answer = canNotificationBeSent();
function canNotificationBeSent(){
   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) {
      return true;
    }
  return false;
}
​

if it is still doesn't work, could you please log the count variable and share the results.

 


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

Hi @Kendra F 

Did it work for you?


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

kfitch
Tera Contributor

The notification didn't fire using this. My Notification is on the Incident Table, so wouldn't that check the Incident for changes and not the Task?