- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 12:29 AM
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2022 02:45 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 08:32 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-06-2022 11:58 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2022 02:45 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-04-2025 09:57 AM
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.