Send notification when all incident tasks are completed

Szilard
Tera Guru

Hello Community!

 

I have a need to send notification to the incident assignee when all the incident tasks are closed.

I have searched for some solution and I found this: https://community.servicenow.com/community?id=community_question&sys_id=094c8b65db9cdbc01dcaf3231f96...

I made my own version of this BR:

table: incident_task

after, insert/update, condition: state changes to closed complete

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

	var gr = new GlideRecord('incident_task');
	gr.addQuery('incident', current.sys_id);
	gr.addQuery('state','!=', 3);                              
	gr.query();
	if (gr.hasNext()) {
		
	}
	
	else {
		gs.eventQueue('incident.task.closed', current, current.incident.number, current.incident.assigned_to);	
	}		

})(current, previous);

My problem is: anytime when I close a task, the notification triggers even though it should only when all tasks are in closed state.

The notification definition itself hasn't got any other trigger condition.

Can someone please help me out?

1 ACCEPTED SOLUTION

Szilard
Tera Guru

Hello Everyone,

 

for those who interested,  finally have the solution, here is the code:

var count = 0;
var gr = new GlideAggregate('incident_task');
gr.addQuery('incident', current.incident);
gr.addQuery('state', '!=', 3);
gr.addAggregate('COUNT');
gr.query();
if (gr.next()) {
         count = gr.getAggregate('COUNT');
}
if (count >= 1) {
			return;
             }
	else {
		gs.eventQueue('incident.task.closed', current, current.incident.number, current.incident.assigned_to);
 }

 

The problem was in the 3rd line, where I queried in the wrong way, I used current.sys_id instead of current.incident. 

View solution in original post

6 REPLIES 6

Uncle Rob
Kilo Patron

Ok, so your business rule only fires the incident.task.closed event.  Have you looked to see if any other business rules fire that event?  If other business rules fire the event than any notification triggered off that event is sure to fire.

Hello Robert,

 

I am pretty sure this is the only BR that fires this event, because I made this event just for this action.

We haven't used the incident tasks so far, this would be the first time, so no one should have intended to use.

Szilard
Tera Guru

Hello Everyone,

 

for those who interested,  finally have the solution, here is the code:

var count = 0;
var gr = new GlideAggregate('incident_task');
gr.addQuery('incident', current.incident);
gr.addQuery('state', '!=', 3);
gr.addAggregate('COUNT');
gr.query();
if (gr.next()) {
         count = gr.getAggregate('COUNT');
}
if (count >= 1) {
			return;
             }
	else {
		gs.eventQueue('incident.task.closed', current, current.incident.number, current.incident.assigned_to);
 }

 

The problem was in the 3rd line, where I queried in the wrong way, I used current.sys_id instead of current.incident. 

Kendra F
Tera Contributor

I have a similar situation, but I want to send the notification from the Incident Record not the Task record but with the same results. Tried using the Business Rule that works from Incident task record and altering it, but nothing is working so far. 

 

Anyone have anything similar or any ideas?  Thanks.