There was one requirement on case management notifcation of 'case opened'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
7 hours ago
There was one requirement on case management notification of 'case opened' and if the case record has watchlist members, they should be in CC on the email notification. Please suggest how to achieve this, and I tried creating an email script and adding it to email body content but it did not work.
Email script :
(function runMailScript(current, template, email, email_action, event) {
gs.info('Case Number: ' + current.number);
gs.info('Watch List Value: ' + current.getValue('watch_list'));
if (gs.nil(current.watch_list))
return;
var watchList = current.getValue('watch_list');
var userGR = new GlideRecord('sys_user');
userGR.addQuery('sys_id', 'IN', watchList);
userGR.query();
while (userGR.next()) {
gs.info('Found User: ' + userGR.getDisplayValue());
gs.info('Email: ' + userGR.getValue('email'));
email.addAddress(
'cc',
userGR.getValue('email'),
userGR.getDisplayValue()
);
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Hey @ashok17 ,
If you are using the OOTB “Case Opened” notification, you will notice that the email body and subject are configured through an Email Template.
I added the Mail Script to the Email Template, and it is working as expected for me.
Here is the Mail Script I used:
(function runMailScript(current, template, email, email_action, event) {
// Check if the watch_list is empty
if (current.watch_list.nil()) {
return;
}
// watch_list is already a comma-separated string of sys_ids.
// Passing the string directly avoids array coercion issues.
var watcherIds = current.watch_list.toString();
var userGR = new GlideRecord("sys_user");
userGR.addQuery("sys_id", "IN", watcherIds);
userGR.addQuery("email", "!=", "");
userGR.query();
var count = 0;
while (userGR.next()) {
email.addAddress(
"cc",
userGR.getValue("email"),
userGR.getDisplayValue()
);
count++;
}
})(current, template, email, email_action, event);This script retrieves the users from the Case Watch List and adds their email addresses to the CC field of the Case Opened notification.
Also, in the notification’s “Who will receive” section, remove the Watch List from the recipient list, since the Watch List members are being added to CC through the Mail Script.
If you find this solution helpful, please consider marking it as Helpful.
Thank you!