Ankur Bawiskar
Tera Patron
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 01-09-2025 05:34 AM
Often, we need to send only the latest attachment via email. However, using the "Include attachment" checkbox in notifications sends all attachments, making it impossible to send just the latest or a specific attachment.
To address this, follow these steps:
1) Create business rule which is After Insert on sys_email with correct condition for table name
2) Use the below script to pick latest attachment
(function executeRule(current, previous /*null when async*/) {
var s_Attach = new GlideRecord('sys_attachment');
s_Attach.addEncodedQuery('table_sys_id=' + current.instance);
s_Attach.orderByDesc('sys_created_on');
s_Attach.setLimit(1);
s_Attach.query();
if(s_Attach.next()){
var rec = new GlideRecord('sys_email_attachment');
rec.initialize();
rec.attachment = s_Attach.sys_id;
rec.file_name = s_Attach.file_name;
rec.source = 'notification';
rec.content_disposition = 'attachment';
rec.email = current.sys_id;
rec.insert();
}
})(current, previous);
Comments
RixelB
Giga Contributor
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
07-28-2025
11:00 PM
It is not a good practice to create business rules in the [sys_email] table from an architecture perspective.