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
11-06-2020 05:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2020 10:32 AM
Thanks Drew. Exactly what the Dr. ordered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-31-2022 03:47 AM
Hey Drew,
This code is really helpful. Thanks alot! However, I am facing an issue with the attachment name in the record (RITM). The name doesn't show up and when clicked, it gets downloaded as 'sys_attachment' (file name is 'How to configure') even when the proper file name is given in the script.
Any idea what could be the reason? Thanks in Advance!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2019 08:55 AM
I got around the issue of attachments link not working for non roled users by
creating a knowledge article and adding an attachment to it,
publishing it,
then referencing its attachment from the email notification script
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var url='/sys_attachment.do?sys_id=1d9ab0f31b5db300cee5ed7cee4bcb08&sysparm_viewer_table=kb_knowledge&sysparm_viewer_id=497a30f31b5db300cee5ed7cee4bcb81'; //--had to add the attachment to a KB article in order to be able to allow non-roled users to access the attachment
template.print ('<a href="' + url + '">Click to download the floor plan</a>');
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2020 08:58 AM
My notification is being triggered by an event that's generated by an RITM workflow. The attachment can be anywhere. I set up a 'before insert' business rule on the sys_email table:
Condition:
current.instance.cat_item == 'sys_id of the catalog item' && current.subject == 'my subject'
Script:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.get('sys_id of the attachment');
var content = new GlideSysAttachment().getContentStream(grSysAtt.sys_id);
new GlideSysAttachment().writeContentStream(current, grSysAtt.getValue('file_name'), grSysAtt.getValue('content_type'), content);
})(current, previous);