- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2017 11:12 AM
So I've implemented the following mail script for Users from the Watch List to be cc'd and it works great. Problem is, we also want to include email addresses added manually to the Watch List (e.g. a Distribution List email address) but I'm hitting a wall on how to write this in or if it needs to be a different mail script altogether. Basically, CC everything from the Watch List and not just Users in the system but also email addresses. Any help would be appreciated.
if (!current.watch_list.nil()) {
//get watch list addresses and add to cc
var watcherIds = current.watch_list.split(",");
//get user records
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", watcherIds);
user.addQuery("notification", 2); //email
user.addQuery("email", "!=", "");
user.query();
while (user.next()) {
//add to cc list
email.addAddress("cc", user.email, user.getDisplayValue());
}
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2017 12:32 PM
This works for me:
var watcherIds = current.watch_list.split(',');
for (var i=0;i<watcherIds.length;i++) {
if (watcherIds[i].indexOf('@') > -1) {
email.addAddress("cc", watcherIds[i], watcherIds[i]);
} else {
var userVals = getUserEmail(watcherIds[i]);
if (userVals.length > -1) {
email.addAddress("cc",userVals[0],userVals[1]);
}
}
}
function getUserEmail(inId) {
var vals = [];
var user = new GlideRecord("sys_user");
user.addQuery("sys_id",inId);
user.addQuery("notification", '2'); //notifications enabled
user.addQuery("email", "!=", "");
user.query();
if (user.next()) {
vals.push(user.getValue('email'));
vals.push(user.getValue('user_name'));
}
return vals;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2017 10:58 AM
There appears to be a spelling error in line 9 of the code. Should be:
email.addAddress("cc", watcherIds[i], watcherIds[i]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2017 11:02 AM
Yea... I caught that but still no luck.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2017 02:07 PM
It doesnt matter if you dont pass the display values in addAddress.
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-01-2017 12:32 PM
This works for me:
var watcherIds = current.watch_list.split(',');
for (var i=0;i<watcherIds.length;i++) {
if (watcherIds[i].indexOf('@') > -1) {
email.addAddress("cc", watcherIds[i], watcherIds[i]);
} else {
var userVals = getUserEmail(watcherIds[i]);
if (userVals.length > -1) {
email.addAddress("cc",userVals[0],userVals[1]);
}
}
}
function getUserEmail(inId) {
var vals = [];
var user = new GlideRecord("sys_user");
user.addQuery("sys_id",inId);
user.addQuery("notification", '2'); //notifications enabled
user.addQuery("email", "!=", "");
user.query();
if (user.next()) {
vals.push(user.getValue('email'));
vals.push(user.getValue('user_name'));
}
return vals;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-10-2018 05:01 AM
Hi Jon
What does current here refer to?
Are you calling this mail script from any BR or script Inc?
I too have a similar requirement but have no clue on how to send the parameters to the notification.