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

How long has that been there - and I've never seen it?



Every day people... every day I learn something like this. That's why I love this community.


FYI - see section 7 here... there are some caveats about limits.



Email Notifications - ServiceNow Wiki


Thank you. But this only includes attachments that users who actually order the item attach. I am looking to attach an attachment that I have attached to the catalog item. It's the same attachment each time.


I'm afraid I don't see a way to attach files that are not part of the current record - only links. Sorry.



I invite you to open an enhancement request if you are so inclined. Our product teams are listening.



Enhancement requests: Tell us how you would improve the ServiceNow product


TE2
Kilo Contributor

Okay thank you.