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

You can check below thread from Jim Coyne which may be useful:



Sending Documents in an Email Notification



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Doesn't look like that will accomplish what I need, as the attachment is submitted when the user logs the catalog request. The attachment will end up attached to the RITM automatically at this point, and that is what I need to have emailed out.


An update... I have changed to using an event and normal email notifications, and had the email notification trigger off of the RITM table, with the "Include attachments" attribute. It's working as expected now.


Ideally, it should send all the files attached to the record but as ctomasi pointed out, it might be happening because of the size limit of the email.



Try attaching 2 small files and test.


And yes, all the files needs to be attached to the record for which the email is triggered.