Populating an image from the sys_attachment table to be within an email notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 09:22 AM
Basically, I have a story that wants an email notification sent out to the caller, when the state hits "Resolved". If the field "Picture of issue" ( field type = image) is populated with an image, they want that image included as an inline image and not as an attachment.
My approach has been to create an mail script and then call that script within the email notification. Where I am currently stuck - I have been able to target the correct attachment on the attachments table but im not sure how to then populate the actual image within the email body. Any help would be appreciated!
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// If there is no picture within the field
if (gs.nil(current.u_picture_of_issue)) {
email.setSubject("None Picture Email");
template.print("No picture in email");
return;
}
// If there IS a picture within the field
var attachGR = new GlideRecord("sys_attachment");
attachGR.get(current.getValue("u_picture_of_issue"));
attachGR.query();
while(attachGR.next()){
var attachFileName = attachGR.getValue('file_name');
}
})(current, template, email, email_action, event);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2023 10:30 AM
Hi @Gaspy,
Upload image in image table and try this in email scripts to bring it in email body.
var img = "/ImageName.png"; // add image name here
var instance = gs.getProperty("instance_name");
var link = "https://" + instance + ".service-now.com";
template.print('<img src="' + link + img + '">');
Thanks,
Sagar Pagar