Set notification recipients dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 02:20 PM
I Created an email script to add the caller of the incident to the notification recipients but when I call it in the body of the notification nothing happens.
Here is the script
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// && current.caller_id != current.u_on_behalf_of
if (!current.caller_id.nil()&& current.caller_id != current.u_on_behalf_of) {
//get caller addresses and add to cc
//get user records
var user = new GlideRecord("sys_user");
user.addQuery("sys_id", current.caller_id);
user.addQuery("notification", 2);
//email
user.addQuery("email", "!=", "");
user.query();
while (user.next()) {
//add to cc list
email.addAddress("cc", user.email, user.getDisplayValue());
}
}
})(current, template, email, email_action, event);
Is there a way to get this to work or I need to go and create an event, a business rule, and use event parm
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 02:42 PM
Hi rez,
Try replacing
email.addAddress("cc", user.email, user.getDisplayValue());
with
email.addAddress("cc", user.email.toString(), user.getDisplayValue());
Hopefully, this will resolve your query.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2022 06:17 PM
Try changing
email.addAddress("cc", user.email, user.getDisplayValue());
to
email.addAddress("cc", user.getValue('email'), user.getDisplayValue());
also add a log inside while loop to test whether code is running
Harish