How to embed an attachment from a catalog item within an email notification?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-13-2016 11:14 AM
I have created a catalog item and on the back end have attached 2 documents that are now in the sys_attachment table. I want these two attachments to be sent within an email each time it is fired (the email is part of my workflow for the catalog item). I don't want it to exist as a link; as this code that I've been using on an Email script does:
printattachments();
function printattachments() {
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id','');
gr.query();
while (gr.next()) {
template.print('Attachment: <a href="https://' + gs.getProperty("instance_name") + '.service-now.com/sys_attachment.do?sys_id=' + gr.sys_id + '">' + gr.file_name + '</a>');
}
}
I want the attachments to actually appear as attachments within the email. I saw on the wiki that you can use the
GlideSysAttachment.copy('sourcetable', 'sys_id', 'destinationtable', 'sys_id');
script, but I don't know what to put in for the 'destinationtable' and the 'sys_id' that follows that. The attachments do exist in the 'sys_attachment' table so I'm assuming that would go in the sourcetable part, but still don't know what to put in the 'sys_id' part. I also have no idea if this should be an email script or something else.
Thoughts?
Thanks!
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2017 04:49 PM
Evening Chuck,
Do you know of any recent ways to incorporate the attachment into the email notification via workflow? I am using a mail script currently to link to the attachment, but the users getting this email are not ServiceNow users so the link is broken for them.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-20-2017 08:52 PM
Hi Shane,
Sorry, I don't know of a way to do that within a workflow (or elsewhere.) FWIW, Links are still the safest way to go with attachments. Most mail systems have a 10-25MB limit on attachments so adding them can be risky.
If you are having issues with the links not working, have you validated that the links are valid?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 11:15 AM
I am not sure how I can get this accomplished via a normal email notification outside of the workflow. The business case is that the catalog item being requested involved a PDF template that the user is to download, fill out, and then attach to the catalog request form. A notification will then be sent to a specific email address, with the PDF submitted to the request.
Any idea how I can best accomplish this? The notification via workflow is working... but it is sending the link attachment and the users getting the email are not ServiceNow users.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 11:54 AM
Hi,
This can be done by configuring the After Insert Business Rule on the desired table say on Requested Item table with the below code:
GlideSysAttachment.copy('sourcetable', 'Sys Id of the Attachment', 'destinationtable', current.sys_id);
E.g.
GlideSysAttachment.copy('sc_cat_item', 'Attachment sys id', 'sc_req_item', current.sys_id);
You can attach both of your document to say one of the catalog Items under Maintain Items module and once attached you can get the sys id of both the docs from the sys_attachment Table.
After configuring your Business Rule in the Notification which you have configured say on the Requested Item table make sure to check the "Include Attachment" checkbox as True.
This worked for me for sending Attachment for one of my catalog Item. Let me know if you have any issues on the same.
Hope this helps.Mark the answer as correct/helpful based on impact
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2017 11:56 AM
My issue is that the attachment ID would always change, as the user is uploading a new PDF to the request catalog item each time.