Send latest attachment in email notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 09:22 PM
Hi,
We have requirement to attach latest attachmnet from security response task record to respective email, it should not send all attachment those are available on task record.
Also we do not want that attachment to be added as URL in email.
Let me know if anyone have idea on this.
Thanks in advance.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 09:59 PM
@Pranali18 To achieve this in ServiceNow, you can use a custom email notification script to handle attaching only the latest attachment from the Security Response Task record.
You can add this script in the Script of the Notification record, so it executes when the email is sent.
// Ensure you're working with the current Security Response Task record
var taskGR = current; // Assuming 'current' is the Security Response Task record
if (taskGR) {
// Fetch the latest attachment for this task record
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_sys_id', taskGR.sys_id);
attachmentGR.orderByDesc('sys_created_on');
attachmentGR.setLimit(1); // Only get the latest attachment
attachmentGR.query();
if (attachmentGR.next()) {
// Attach the file content directly to the email, not as a URL
var attachmentDoc = new GlideSysAttachment();
var attachmentStream = attachmentDoc.getBytes(attachmentGR);
// Attach to email
email.addAttachmentStream(
attachmentGR.file_name,
attachmentStream,
attachmentGR.content_type
);
}
}
You can amend code as well but approch should be same.Hope this will help you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2024 11:23 PM
Hi @Abhay Kumar1 thanks fro quick reply. I used this in email script and call that in notification using ${mail_script:scriptName}. but unfortunately it's not working.