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-26-2018 05:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 12:49 AM
You've removed the default mail script syntax that populates when you create a new mail script, you need to keep that in, your complete mail script should look like below:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
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]);
}
}
}
})(current, template, email, email_action, event);
rename it: add_watchlist_to_cc
and call it in your message body with: ${mail_script:add_watchlist_to_cc}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 03:38 AM
No it didn't fetch me the required result
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2018 03:59 AM
Add in some debugging lines and put in the responses here, i've added some examples in the code below, you can find the outputs in script log statements. You need to learn to debug your code, coming back on here and just saying 'it didn't work' isn't very helpful.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
if(!current.watch_list.nil()){
var watcherIds = current.watch_list.split(',');
gs.log('Hi, i made it here and this is the watch list: ' + watcherIds);
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();
gs.log('there are ' + user.getRowCount() + ' records returned');
if (user.next()){
gs.log('good news, i made it here as well');
email.addAddress('cc', user.email, user.getDisplayValue());
}
else{
email.addAddress('cc', watcherIds[i]);
}
}
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2018 04:19 AM
Hi Please remove the CC: from ${mail_script:new_mail_script_name}, it should work
Thanks