how can i add watch list users to cc in the email notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 06:42 AM
hello friends,
i am trying to send the email notifications to the cc ie the user from the watch list.Could you please help me out
please provide with details as i am new to scripting.
Thanks,
venkat
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 07:08 AM
Hello,
There is a page on the docs site that explains exactly how to do this:
Example mail scripts for notifications
You'll need to add the code below to a mail script and then call it in your notification like: ${mail_script:new_mail_script_name}
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());}}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 07:21 AM
Actually it just occurred to me that some of the addresses in your watch list might not be in the user table, if you use the script below it will iterate through the watchlist and, if it matches a sys id with a user it will add them to cc, if not it will just add the email address.
if(!current.watch_list.nil()){
var watcherIds = current.watch_list.split(',');
for (var i=0; i< watcherIds.length; i++) {
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", watcherIds[i]);
user.addQuery("notification",2);
user.addQuery("email","!=","");
user.query();
if (user.next()){
email.addAddress('cc', user.email, user.getDisplayValue());
}
else{
email.addAddress('cc', watcherIds[i]);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 02:12 AM
Thanks for your response.
but it didnt helped me.
mail is generating but cc name is not included.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 02:37 AM
OK, did you add this as a mail script and then call it in the message body of the notification? If you want any more assistance with it share some screenshots or something of what you configured.