- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2025 10:27 AM - edited 04-16-2025 10:33 AM
Hi,
I have a notification that includes links to several email templates.
When a user selects any template, it open's a new email with the "To" field automatically populated with our instance mail ID
I would like some guidance on how to achieve the following functionality
Within that same email, they should also be able to see the CC and BCC recipients, which are unique based on Record-> location -> email records.
Could anyone please advise how I can implement this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2025 12:40 PM
Hello @Sindhu50 ,
This is not possible via Email Templates since they are static. But you can achieve this with Email Scripts. Here is an example. Just change the name and the values of the first four variables as per your requirements.
Name: email.link.with.dynamic.recipients
Script:
(function runMailScript(current, template, email, email_action, event) {
var linkText = 'Click here to reply';
var subject = 'Email subject of reply goes here';
var cc = [
current.assigned_to.email.toString(),
current.assignment_group.manager.email.toString()
].toString();
var bcc = current.opened_by.email.toString();
var to = gs.getProperty('instance_name') + '@service-now.com';
var body = email.watermark;
var url = gs.getMessage('mailto:{0}?cc={1}&bcc={2}&subject={3}&body={4}', [
to, cc, bcc, encodeURIComponent(subject), encodeURIComponent(body)
]);
var link = gs.getMessage('<a href="{0}">{1}</a>', [url, linkText]);
template.print(link);
})(current, template, email, email_action, event);
Then put this in the Message of your Notification, where the email link shall appear:
${mail_script:email.link.with.dynamic.recipients}
The notification will look like this:
Clicking the link will open a new Email:
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2025 12:40 PM
Hello @Sindhu50 ,
This is not possible via Email Templates since they are static. But you can achieve this with Email Scripts. Here is an example. Just change the name and the values of the first four variables as per your requirements.
Name: email.link.with.dynamic.recipients
Script:
(function runMailScript(current, template, email, email_action, event) {
var linkText = 'Click here to reply';
var subject = 'Email subject of reply goes here';
var cc = [
current.assigned_to.email.toString(),
current.assignment_group.manager.email.toString()
].toString();
var bcc = current.opened_by.email.toString();
var to = gs.getProperty('instance_name') + '@service-now.com';
var body = email.watermark;
var url = gs.getMessage('mailto:{0}?cc={1}&bcc={2}&subject={3}&body={4}', [
to, cc, bcc, encodeURIComponent(subject), encodeURIComponent(body)
]);
var link = gs.getMessage('<a href="{0}">{1}</a>', [url, linkText]);
template.print(link);
})(current, template, email, email_action, event);
Then put this in the Message of your Notification, where the email link shall appear:
${mail_script:email.link.with.dynamic.recipients}
The notification will look like this:
Clicking the link will open a new Email:
Regards,
Robert