How to send email notification with physical attachment
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 07:58 AM
How to send email notification with physical attachment
I have used this below script in email script notification, but its sending the attachment as link but i want to send real attachment in email please guide me how to do
notification
var eve = "93e903b1db505700d7fa5040cf9619e4";
var gr =new GlideRecord('sys_attachment');
gr.addQuery('sys_id','IN',eve);
gr.query();
while(gr.next()){
template.print('Attachment: <a href="http://'+gs.getProperty("instance_name")+'.service-now.com/sys_attachment.do?sys_id='+ gr.sys_id + '">' + gr.file_name + '</a>\n');
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2019 06:12 AM
Hi Drew,
Could you please share the screenshot?
I tried using your code but no attachment got attached to my triggered email.
We have only one attachment to be attached in email notification so i have commented if condition.
Below is the code could you please correct me.
var myStringArray = "288ed2c4db333300a4798742399619fd";
//This field wasn't used so I commented it out
//var att =[];
var sys = current.instance;
//var sys = " 8f9389b5c0a8016401715c208ff9bf48";
gs.log("test"+sys);
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery('table_sys_id',sys);
grSysAtt.query();
while(grSysAtt.next()) {
var asys = grSysAtt.sys_id;
gs.log('test 2'+asys);
//if(myStringArray.indexOf(asys)>=0){
var content = new GlideSysAttachment().getContentStream(grSysAtt.sys_id);
new GlideSysAttachment().writeContentStream(current, grSysAtt.getValue('file_name'), grSysAtt.getValue('content_type'), content);
gs.log("test name" + grSysAtt.getValue('file_name'));
//}
}
})(current, template, email, email_action, event);
Thanks and Regards,
Meenal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2019 09:00 AM
Hey Meenal,
I have the sys variables commented differently than yours. Try flipping the comment and see if that works.
//var sys = current.instance;
var sys = " 8f9389b5c0a8016401715c208ff9bf48";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2020 06:07 AM
When I use this, it attaches the file to the record that is sending the notification (which makes sense, with 'current' being specified in 'writeContentStream'), not the notification email.
For example, my notification is triggered from a workflow tied to a requested item. When the notification fires, this script attaches the file to the requested item.
Edit: I got it to work. You have to make sure "include attachments" is checked on the notification "what it will contain" tab. So, the script copies the attachment to the originating record, and "include attachments" makes the notification grab files that are attached to the record. Sort of a weird way to do it, but it works.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2021 04:31 PM
Thanks, enabling "include attachments" made it work, but it also included all other attachments from the RITM. I think this will be fine for now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 03:40 AM
Hey Dave,
I tried Drew's code and also checked Include Attachments in the notification. Still the file didn't attach to the email on Outlook. Any suggestions what could be the possible reason?
Thanks In Advance!