Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding Recipient in the Email Script using addAddress("To", xyz@gmail.com)

vanshikamai
Tera Contributor

Hey all,
I want to know a way to add recipients in the email script.  I know cc and bcc words but not sure if  "To" also works . I am triggering the notification via an event which will get triggered via an SLA. I am sending the email to filtered users so cannot use the recipient field on "who will receive"
Is there anything like addRecipient() . Your help is truly appreciated. Thankyou.

3 REPLIES 3

Sreeram Nair
Tera Guru

When adding recipients dynamically within an email script, you can use the method

email.addAddress(type, address, displayName)

where the type parameter supports "cc" and "bcc" to add recipients as carbon copy or blind carbon copy. However, using "to" as a type generally does not work as expected in notifications triggered via events, because the primary recipients (“To” field) are controlled by the notification configuration or the event itself. The best practice is to define the “To” recipients either through the notification’s Who Will Receive section or by passing user information through the gs.eventQueue() call when triggering the event.

 

The email script is mainly used for adding or modifying CC or BCC addresses, not for defining the primary recipients. For example, you can include email.addAddress("cc", "extra@company.com", "Extra User"); within your mail script to copy additional users. This approach ensures reliable email delivery and proper handling of recipients as designed within ServiceNow’s notification framework.


ɪꜰ ᴍʏ ᴀɴꜱᴡᴇʀ ʜᴀꜱ ʜᴇʟᴘᴇᴅ ᴡɪᴛʜ ʏᴏᴜʀ Qᴜᴇꜱᴛɪᴏɴ, ᴘʟᴇᴀꜱᴇ ᴍᴀʀᴋ ᴍʏ ᴀɴꜱᴡᴇʀ ᴀꜱ ᴛʜᴇ ᴀᴄᴄᴇᴘᴛᴇᴅ ꜱᴏʟᴜᴛɪᴏɴ ᴀɴᴅ ɢɪᴠᴇ ᴀ ᴛʜᴜᴍʙꜱ ᴜᴘ.




ʙᴇꜱᴛ ʀᴇɢᴀʀᴅꜱ


ꜱʀᴇᴇʀᴀᴍ

Sheldon  Swift
ServiceNow Employee
ServiceNow Employee

Hi @vanshikamai - Type must be either "cc" or "bcc". If you're triggering the notification via an event, can you pass the recipients in parm1 or parm2 when you fire the event? Either parameter will accept a comma-separated list of values.

Ankur Bawiskar
Tera Patron
Tera Patron

@vanshikamai 

not possible to set recipients via email script, only CC and BCC is supported.

what's the use-case that you are trying to add recipient via email script? why not set those when event triggers and include them in either event parm1 or event parm2?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader