How to email attachment from Attachment (sys_attachment) table

chrish5
Giga Guru

When a CSV file with a specific name (something like xyz.csv) is inserted into the Attachment (sys_attachment) table, I would like to send that attachment via email.  Can this be accomplished?  

1 ACCEPTED SOLUTION

chrish5
Giga Guru

Thanks your for your suggestions. 

I ended up creating an after insert business rule on the sys_attachment table with a condition of current.table_name == 'sc_req_item' and the following script.  

(function executeRule(current, previous /*null when async*/) {
var ritmObj = new GlideRecord('sc_req_item');
if (ritmObj.get(current.table_sys_id)) {
gs.eventQueue('sc_req_item.jct.attachment.add', ritmObj, current.file_name);
}
})(current, previous);

 

This then created the highlighted event which then triggered the notification with the attachment. 

I hope this is helpful for others. 

View solution in original post

6 REPLIES 6

Aman Kumar S
Kilo Patron

Hey,

Follow below article to achieve this:

Adding attachments to Email

 

Feel free to mark correct, If I answered your query.

Will be helpful for future visitors looking for similar questions 🙂

Best Regards
Aman Kumar

Jaspal Singh
Mega Patron
Mega Patron

Hi Chrish,

You can create notification on sys_attachment table to make this work? Whom has this to be sent out that may be possibly need some event so that you can pass parameters in gs.eventQueue() accordingly.

Hi Jaspal,

I created the notification on the sys_attachment table to send when record is inserted and a condition of File Name is xyz.csv.  I also checked the Include Attachments" box.  The notification is being triggered when a new xyz.csv file is inserted into the sys_attachment table, but that xyz.csv files that triggered the notification is not be attached to the email that is being sent.  What am I missing here? 

Thanks,

Chris

Allen Andreas
Administrator
Administrator

Hi,

As mentioned by one poster, you can simply create a notification on the attachment table, build conditions as needed, set recipients, and your message, and that's about it. Should hopefully be pretty standard with no code really needed.

Please mark reply as Helpful, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!