The CreatorCon Call for Content is officially open! Get started here.

Notification Email Script: Adding an email address to the 'TO' field

Jamsta1912
Tera Guru

Hello all,

I want to add some email addresses to the 'TO' field of an email notification, dynamically using an email notification script. There's a recent post asking the same thing here: https://community.servicenow.com/community?id=community_question&sys_id=947dff3fdb5adc549e691ea66896...

The suggested solution there was to do something like this:

email.addAddress("to","john.copy@example.com","John Roberts");

However that's not working for me, and according to the documentation below, this method can only be used to add recipients to the 'CC' or 'BCC' field. Is there a way to do this for the 'TO' field?

https://docs.servicenow.com/bundle/newyork-servicenow-platform/page/script/server-scripting/referenc...

Thanks

Jamie

1 ACCEPTED SOLUTION

vkachineni
Kilo Sage

You cannot do "to"

Only allowed are "cc" and "bcc"

email.addAddress("cc","john.copy@example.com","John Roberts");

If your notification is a event based one, use the event parm1 / 2 "to" send the notification.
Please mark Correct and click the Thumb up if my answer helps you resolve your issue. Thanks!
Vinod Kumar Kachineni
Community Rising Star 2022

View solution in original post

7 REPLIES 7

MrMuhammad
Giga Sage

Have you tried below?

email.setReplyTo("joe.employee@yourcompany.com");
Regards,
Muhammad

Hello Muhammad, 

That would set the 'ReplyTo' field, rather than add the email address as a recipient to the 'TO' field.

thanks

Jamie

Willem
Giga Sage
Giga Sage

Hi Jamie,

Where are you triggering the email from?

If the user you want to add dynamically is on the field of the table you are triggering the email from you can use "Users/Groups in fields". You can use dot walking as well (accessing fields that are referenced on the table). So for example if an Incident triggers the email and I want to send the notification to the Manager of the caller:

find_real_file.png

 

find_real_file.png

 

 

find_real_file.png

 

find_real_file.png

 

For each record triggering the notification it will add the Manager of the Caller for that specific Incident to the "To" field.

 

Not sure if this is what you are looking for. If it is not, please share where the email address is coming from and why you want to add it via script.

Hi Willem,

The scenario is that the notification is to inform service managers of a major outage. The notification contains a list of impacted sites (which are 'affected locations' against an incident). Each location has a service manager (which is held in a custom reference field to the user table). We only want the email to go to the service managers for the sites affected by this particular major outage. So in this case it does need to be scripted. I have it working using CC, but not using TO, and it seems there does have to be at least one user or email address set statically in the TO field. I think this will have to do!