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

Its hard to tell what's similar and what's not about the request.
Please state the exact scenario you want the notification to fire.

Hello Kendra,

show your script.