doesn't email.addAddress() work for email client templates?

Goran WitchDoc
ServiceNow Employee
ServiceNow Employee

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

4 REPLIES 4

Deepak Ingale1
Mega Sage

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.


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


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

Raj68
Mega Guru

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.html

     

    NOTE: Mark correct or helpful if it helps you.

     

    Warm Regards,

    Raj patel