doesn't email.addAddress() work for email client templates?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2016 01:38 PM
I'm having a problem with mail script and email client templates.
For example if I have a mail_script that just looks like this:
(function runMailScript(current, template, email, email_action, event) {
template.print("my testing");
// Add your code here
})(current, template, email, email_action, event);
It will work and the "my testing" will come in the body of the mail client when it pops up.
But I also want to set a specific address in the "CC". So I thought I just do this:
(function runMailScript(current, template, email, email_action, event) {
template.print("my testing");
email.addAddress('cc','test@example.com');
// Add your code here
})(current, template, email, email_action, event);
But then the code breaks and the template.print doesn't work anymore and nothing happens.
I don't get what is wrong here.
Can add that I also tested with email.setSubject("testing"); without any success either
//Göran
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2016 08:28 PM
Hi Goran,
Did you try to directly set the "cc" field available on client template?
Also setting to and cc fields like ${assigned_to} where assigned_to is column on current record works in dynamic way as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-23-2016 11:58 PM
yea, those works,
But in this case I guess I need to do it in the mail script since in my finale version it would be variables etc. that will be in the email.addAddress. This was just a basic test to try and get it going. and the email.addAddress should fit like a hand in a glove, but somehow it doesn't work. So I'm wondering if this method only notifications and not email client templates.
//Göran
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018 10:18 PM
Hi Goran
I understand this is a very old post. I am also in the similar situation and email.addAddress is not working from me? Did you found the root cause?
-Harsh

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-30-2018 10:50 PM
Hi Goran,
Hope below code will help you to reach your requirement:
- Navigate to System Policy > Email > Client Templates.
- Select an existing template or create one. For example, select the Incident Template record.
- Configure the form to add the From field.
- Enter a script to add a default value to the From field.
For example, the following script displays the current user name and the current user email address.
javascript:gs.getUserDisplayName()+" <"+ gs.getUser().getEmail()+">"
https://docs.servicenow.com/bundle/london-servicenow-platform/page/administer/notification/task/t_SetFromAddClientTemp.htmlNOTE: Mark correct or helpful if it helps you.
Warm Regards,
Raj patel