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.

How to add attachments while sending out an email notification?

Vandana M V
Tera Contributor

Hi,

I used the below script in a business rule to add a static attachment along with one of the email notification.

(function executeRule(current, previous /*null when async*/ ) {// Add your code here

var grSysAtt = new GlideRecord('sys_attachment');

grSysAtt.get('ab1fc95cdbaf101082f21780399619ff'); //mention your attachment sys_id

var content = new GlideSysAttachment().getContentStream(grSysAtt.sys_id);

new GlideSysAttachment().writeContentStream(current, grSysAtt.getValue('file_name'), grSysAtt.getValue('content_type'), content);

})

(current, previous);

The script is working fine, but the attachment is not being sent along with the email notification.

Currently the target table in BR is sys_email, on which its not working but when I gave the table as sys_email_logs, the attachment was correctly attached to the log during testing. Please help me to find why exactly is this BR not working on sys_email table.

Regards,

Vandana M V

2 REPLIES 2

SanjivMeher
Mega Patron
Mega Patron

Is this BR on the sys_email table?

Why dont you just copy the attachment to the email?

Below article can help

https://www.servicenow.com/community/itsm-articles/copy-attachments-to-email-client-template/ta-p/23...

 


Please mark this response as correct or helpful if it assisted you with your question.

Hi Sanjiv,

Thank you for the response. I have used the same code mentioned in the community link which you mentioned as well. But on sys_email table it does not work.

Regards,

Vandana M V