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

Hi Allen

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

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.