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
06-21-2018 10:12 AM
you can also refer:
Add attachment to Notification Email
Document attachments on an email notification
Getting attachment in Email rather than link
Include Attachments in an Email Notification - ServiceNow Wiki
how can I add an attachment to send out a notification
Let me know if you need more help.
Thanks,
Rajashekhar Mushke
Community Leader - 18
Thanks,
Rajashekhar Mushke
Rising star : 2022 - 2024
Community Leader -2018
Connect me on LinkedIn : Rajashekhar Mushke

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-21-2018 10:20 AM
Yea, my link posted above goes to one that is relevant to his post. Thanks for helping.
Just unsure about spamming 4-5+ links is the best way to go about this.
We'll have to see what the OP says in regards to the assistance that was provided thus far.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2018 09:41 PM
Hi All,
Thanks for your reply i got solution for this requirement by following code
var myStringArray = workflow.scratchpad.parm; (This is attachment sys id from the sys_attachment table)
var att =[];
var sys = current.instance;
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery('table_sys_id',sys);
grSysAtt.query();
while(grSysAtt.next()) {
var asys = grSysAtt.sys_id;
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);
}
Thanks
Ramesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2019 01:21 PM
@Rameshnathan
Your script above...is that a mail script, workflow run script, or something else? Could you provide some screenshots of what you did?
I am trying to send an email with a PDF file actually attached to it and I am not having any luck. I don't want to send URL/links and that's all anyone suggest.
Please mark this response as correct and/or helpful if it assisted you with your question.
Steven
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2019 11:30 AM
Hey Steven,
I was able to get it to work with Rameshnathan's code. Here is the relevant code that I have in an email script.
//These are the sys_ids of the attachments that you want to attach to the email. You can find the sys_id by right-clicking the attachment on the attachment table and copying the sys_id.
var myStringArray = "57a856841ba937007b1ca7d4bd4bcb45,eba856841ba937007b1ca7d4bd4bcb46";
//This field wasn't used so I commented it out
//var att =[];
//Current.Instance returned undefined for me in my logging. I attached both of my attachments to the email notification that I wanted to use. Then I went to the sys_attachments table and found both of my attachments. For those attachments it showed that the table sys ID was 3d68b54c1b2937007b1ca7d4bd4bcb47 so I substituted the variable sys for that sys_id.
//var sys = current.instance;
var sys = "3d68b54c1b2937007b1ca7d4bd4bcb47";
//This queries the sys_attachment table for all attachments where the table_sys_id is the sys_id you used above.
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery('table_sys_id',sys);
grSysAtt.query();
while(grSysAtt.next()) {
var asys = grSysAtt.sys_id;
//This if statement checks the attachments that you used in myStringArray and makes sure that it only grabs those attachments.
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'));
}
}
Let me know if you need any screenshots or help!