- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 03:04 AM
Hi All,
I require that when the additional comments on the sc_req_item change an email notification is sent to the person who is assigned to the task related to that item. I found an earlier post on here and tried to replicate the business rule and notification, but I'm not getting any email notification firing. Below is the business rule setup and email notification setup. Do I need to add somewhere to the notification the business rule that is being used?
I was also wondering if the sc_req_item has multiple tasks related to it, would this send a notification to the assigned to person on each task?
Any help as to where I've gone wrong is greatly appreciated.
Business Rule:
Email Notification
.
Email Template
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-08-2017 11:19 PM
Hey Sam,
Sorry was caught up with my implementation specialist exam.
This is puzzling, the order of tasks shouldn't make any difference, can you please modify the BR as follows -
function executeRule(current, previous /*null when async*/) {
var email_to = [];
var sc_task = new GlideRecord('sc_task');
sc_task.addQuery('request_item',current.sys_id+'');
sc_task.addActiveQuery(); //eliminates the inactive/closed tasks, optimizes the results
sc_task.query();
while (sc_task.next()){
gs.log("sam1");
if (sc_task.assigned_to == "" || sc_task.assigned_to == null){ //included the null keyword as sometimes the system doesn't compare successfully with ""
gs.log("sam2 "+sc_task.assignment_group.manager);
email_to.push(sc_task.assignment_group.manager+'');
}
else{ //added an else to optimize the query
gs.log("sam3 "+sc_task.assigned_to);
email_to.push(sc_task.assigned_to+'');
}
}
gs.log("sam4 "+email_to);
gs.eventQueue("sc_req_item.commented.itil", current, email_to.join(), gs.getUserName());
})(current, previous);
I've just tweaked the logs and the email_to.push statement.
Please run all the 4 use cases and share the logs/results:
1. both tasks have assigned to
2. both tasks don't have assigned to
3. task 1 has assigned to & task 2 doesn't
4. task 2 has assigned to & task 1 doesn't
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 05:14 AM
Hi sakshi,
I've tried to amend the script to cater for when a log is not assigned to an individual that the notification gets sent to the assignment groups manager. On my test example, I have 2 tasks open. Both of these are not assigned to an individual. One is assignment group of Service Desk and one is assignment group Servicenow Admin. The notification however is not getting sent to both manages, only the manager of the Servicenow Admin Group, the manager of the Service Desk is not being sent a notification
If the tasks are assigned to individuals, the person assigned to the first task in the list is getting 2 emails sent (one just sent to them, and the second sent to both assigned to people), the second just gets 1 as expected.
If the task is closed (active == false) the notification is still being sent when additional comments are updated.
Below is the business rule, I need it to send the notification to the group managed if assigned to is empty. If assigned to is populated send 1 notification to each assigned to. If task is closed don't send notification. Any help as to where I have gone wrong is greatly appreciated.
(function executeRule(current, previous /*null when async*/) {
var email_to = [];
var sc_task = new GlideRecord('sc_task');
sc_task.addQuery('request_item',current.sys_id+'');
sc_task.query();
while (sc_task.next()){
if (sc_task.active == 'false'){
return;
}
if (sc_task.assigned_to == ""){
email_to.push(sc_task.assignment_group.manager);
}
if (sc_task.assigned_to){
email_to.push(sc_task.assigned_to);
}
}
gs.eventQueue("sc_req_item.commented.itil", current, email_to.join(), gs.getUserName());
})(current, previous);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2017 11:58 PM
Hey Sam,
While your code logic looks okay, I've made some minor modifications to code snippet as below:
(function executeRule(current, previous /*null when async*/) {
var email_to = [];
var sc_task = new GlideRecord('sc_task');
sc_task.addQuery('request_item',current.sys_id+'');
sc_task.addActiveQuery(); //eliminates the inactive/closed tasks, optimizes the results
sc_task.query();
while (sc_task.next()){
if (sc_task.assigned_to == "" || sc_task.assigned_to == null){ //included the null keyword as sometimes the system doesn't compare successfully with ""
email_to.push(sc_task.assignment_group.manager);
}
else{ //added an else to optimize the query
email_to.push(sc_task.assigned_to);
}
}
gs.eventQueue("sc_req_item.commented.itil", current, email_to.join(), gs.getUserName());
})(current, previous);
Also, another thing we often miss while testing is, our data setup. Please ensure that the group you are selecting has a manager. Also, ensure the assigned to user/manager, both have notification preferences 'enabled' and have an id mentioned in the 'email' field. (they might seem trivial, but in my experience, 50% of the time something doesn't work, data is the culprit, hence the addendum!)
Thanks
Sakshi
P.S.: please mark helpful/correct based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 05:32 AM
Hi Sakshi,
Thanks for all the detail above. Still trying to get to grips with the scripting, never done any before until started with ServiceNow, and still new to SN. I've checked and there was issue with data for one of the managers The script now correctly send notification to assignment group managers if assigned to is blank.
I had 1 RITM with 2 tasks on it. On both task assigned to was populated. This correctly sent a notification to both users, however 1 user got a second notification also sent, any idea why they would get 2?
I also tried where one task was closed. It sent the notification to the assigned to of the open task, but then a second notification sent and this went to both users (the one of the open task and to the one of the closed task, any suggestion as to why this would happen. Below is a screenshot of the Email logs:
The one sent at 13:19 is where both tasks were active. As you can see it sent the notification first to Florence.Orford and then sent another one to both Florence.Orford and to Sam.Mercer.
The one sent at 13:20. This is where one task was closed (assigned to Florence.Orford). Again can see it sent to both first, and then just to sam.Mercer for the second.
Let me know if you need any further information.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 05:47 AM
Hey Sam,
Just hang in there, you are doing great. We were all new to SN at some point!
Coming to the issue at hand, there are 2 possibilities:
1. There are 2 notifications configured. One being sent for the event and one based on the condition (RITM additional comments updated) or 2 separate notifications configured for the same event,
2. The event is getting triggered twice. Can you please paste a screenshot of the event log here?
Once we know the culprit, we'd be able to solve it.
Thanks
Sakshi
P.S.: please mark helpful/correct based on impact
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-26-2017 06:48 AM
Hi Sakshi,
Just had a check and it looks like there was the below business rule that was causing it to fire the notification as well. When I deactivate this, if the 2 tasks are both only assigned to a group and not an individual both group managers get the notification as expected. If 1 task is not assigned to an individual and 1 task is assigned to an individual it is only sending the notification to the manager of the task that is not assigned. If both tasks are assigned then it is only sending 1 notification to the first task in the list, the second person does not get 1.
Business rule that appears to be conflicting:
I've set the above rule to inactive to check what is happening with the rule we have written. Can I check what the above rule does that my rule does not cover?
Both Task unassigned:
Both managers get sent the notification
1 Task is assigned, the 2nd is still unassigned:
Both the user of the 1st task and manager of the second task get the notification
1st task is not assigned and 2nd task is assigned:
Only the manager of the unassigned task is getting the notification, the user the 2nd task is assigned to does not get the notification - not how we want this to work. want both to get the notification like the previous test.
Both tasks are assigned:
Only the user from the first task gets the notification:
Swapped which users are assigned to each task (to show that sam.mercer is setup to get notifications:
Again Only the user from the first task gets the notification:
The Closed one seems to work as expected regardless of which task is still open.
Hope this is the info you need
Thanks once again for all your help.