Pull attachment script

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 12:02 AM - edited 10-08-2024 04:11 AM
Hi,
Quite similar to this thread: Pull watch list emails script I need to pull an attachment from an incident, if the attachment exist, and add it to a Email Client Template to be used for Incident Communication Tasks. The attachment is always called 'Problemrapport.docx' and I thought that I could just fetch that attachment via a Script Include and call that Script Include from the Email Client Template, but it does not seem to work. I am not sure where to call the Script Include from on the template either since it has not scripted fields. Should it work from any field (Cc or Bcc fields for instance) ?
Script name: getAttachmentsFromIncident
var getAttachmentsFromIncident = Class.create();
getAttachmentsFromIncident.prototype = {
initialize: function() {},
attachSpecificFile: function(email, incId, fileName) {
var attachmentGR = new GlideRecord('sys_attachment');
// Query to get attachments related to the incident with the specific file name
attachmentGR.addQuery('table_name', 'incident');
attachmentGR.addQuery('table_sys_id', incId); // The sys_id of the incident
attachmentGR.addQuery('file_name', fileName); // The specific file name
attachmentGR.query();
// Check if attachment exists and attach it to the email
if (attachmentGR.next()) {
// Attach the file to the email
email.addAttachment(attachmentGR);
gs.log('Attachment found and added to email: ' + fileName);
return true; // Indicate that the attachment was added
} else {
gs.log('No attachment found with the name: ' + fileName);
}
return false; // No attachment found
},
type: 'getAttachmentsFromIncident'
};
From the template I guess that this should work:
javascript: new getAttachmentsFromIncident().attachSpecificFile(email, current.incident_alert.source_incident.sys_id, 'Problemrapport.docx');
But alas is doesn't
Can you see why?
Best regards
Thomas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 04:17 AM
Thanks again, Palani
Now the 'Problemrapport.docx' is attached to the Incident Communication Task record from which the Email Client Template is composed and not to the email. I will try a different approach by copying the attachment instead, I guess
Best regards
Thomas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 05:54 AM
You can tick the check box 'Include attachments' checkbox in the 'What it will contain' tab on the Notification. This will ensure attachment of Communication task is copied to the notification
Palani

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2024 11:18 PM
Thanks again, but I am not triggering a notification. I am using the 'Compose' related link on a Incident Communication Task, which uses an Email Client Template. I see no option to enable attachments in Email Client Templates.
Best regards
Thomas