Comment
Kristoffer Mon1
Giga Expert
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
11-21-2019
12:17 PM
I am on London as well, and had to perform some tweaks Adam's original code (very clever stuff) to get this work. When I migrate to "New York" i'll make sure to address this business rule after the upgrade.
The main idea here, was to convert the code to use the 'sys_attachment' table as opposed to the 'sys_email_attachment' table.
(function executeRule(current, previous /*null when async*/) {
var logs = ['Inline Image Email'];
if(current.body.indexOf('[embedded report]') == -1)
{
// if not found, leave everything alone
return;
}
// get email attachments and set them to inline attachments
var attach = new GlideRecord('sys_attachment');
attach.addQuery('table_sys_id', current.sys_id);
attach.addQuery('table_name', 'sys_email');
attach.addQuery('content_type', 'STARTSWITH','image/'); // only images supported
// set any attachments as being inline so they aren't attached
//attach.setValue('content_disposition', 'inline');
attach.updateMultiple();
// get the attachments to loop over
attach.query();
// if
if(attach.getRowCount() == 0)
{
logs.push('No attachments, so nothing to inline');
current.body = current.body.replace('[embedded report]', 'Nothing to attach');
return;
}
var reportContent = '';
// add tags to inline all the images
while(attach.next())
{
reportContent += '<img src="{filename}"/>'
.replace('{filename}', attach.file_name);
}
// replace the tag in quotes since that can't have tags added to it. This should be a smarter regex, but we'll brute force it for now
current.body = current.body.replace('\'[embedded report]\'', '');
current.body = current.body.replace('"[embedded report]"', '');
// add the image tags
current.body = current.body.replace('[embedded report]', reportContent);
gs.info(logs.join('\n'));
return;
})(current, previous);