How to embed an attachment from a catalog item within an email notification?

TE2
Kilo Contributor

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!

19 REPLIES 19

Chuck Tomasi
Tera Patron

Looking to see what I can find...



in the mean time, that Wiki article you got was a bit out of date. You don't need the https:// instance name garbage any more. The system is smart enough to analyze and auto-correct URLs. The template.print line would look more like this today:



              template.print('Attachment: <a href="'/sys_attachment.do?sys_id=' + gr.sys_id + '">' + gr.file_name + '</a>');



TE2
Kilo Contributor

Okay thanks! But I'm still looking to embed the attachment within the email. Not link it. Any ideas on this?


Hi Tagwa,



Nothing yet. All the references I seem to find suggest this is not a very good idea as the attachments may be too big for the receiving email server to accept and could be stripped off if it is not the right file type.


Gaurav Kashyap
Mega Expert

Hi Tagwa,



Please try below -


1. Go to System Notifications --> Email --> Notifications



2. Click on "Advanced view" if not already on it.


find_real_file.png


3. Go to "What it will contain" tab



4. Check the "Include attachments" box


find_real_file.png



Hope this helps.



Regards,


Gaurav