Attachment not sending with Email Notification even with Include Attachment checked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 09:43 AM
Hello,
Our goal is to send out a welcome email after a Lifecycle Event case has been flipped from Draft to Ready. Currently, we are able to send this email but the attachments that sit on the notification do not send with the email, even when "Include Attachments" is checked. Recently we have shifted to triggering our emails with events. Since the notiifcation is failing to include the attachments, is there a way to include the attachments in the business rule we use to trigger the email?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-07-2023 11:08 AM
Hi @aguanci ,
Hope you are doing great.
Below is a proposed solution:
Open the business rule that triggers the email when the Lifecycle Event case is flipped to Ready.
Locate the section of the business rule responsible for sending the email notification. This may involve finding the code that generates and sends the email.
To include attachments in the email, we'll need to modify the code that sets up the email notification. We can utilize the GlideSysAttachment API to attach the files to the email.
Retrieve the attachments associated with the Lifecycle Event case. You can do this by querying the "sys_attachment" table with the relevant "sys_id" of the Lifecycle Event case.
Once you have the attachments, attach them to the email using the GlideSysAttachment API.
sample code snippet for reference :
// Assuming you have already retrieved the sys_id of the Lifecycle Event case in a variable called 'lifecycleEventSysID'.
// Retrieve the attachments associated with the Lifecycle Event case.
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'lifecycle_event'); // Adjust table name as needed.
attachmentGR.addQuery('table_sys_id', lifecycleEventSysID);
attachmentGR.query();
// Assuming you have the GlideEmailOutbound API available to send the email.
var email = new GlideEmailOutbound();
email.setSubject('Welcome to our Lifecycle Event');
email.setBody('Dear User,\n\nWelcome to the Lifecycle Event. We are excited to have you on board.');
// Attach each attachment to the email.
while (attachmentGR.next()) {
var attachmentSysID = attachmentGR.getValue('sys_id');
email.addAttachment(attachmentSysID);
}
// Send the email.
email.send();
Regards,
Riya Verma