

- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-04-2022 02:54 PM
Hi,
Recently someone had asked a question on the forums that grabbed my curiosity, so I decided to dig in and check some things out. Their question was essentially: how to take an attachment variable on a catalog item and embed that attachment within a notification body. This is different than just using the "Include Attachments" checkbox on the notification as that would just include all record attachments as an attachment to the email, but not actually embedding it in the body.
So, I did some quick testing and came up with a few use case examples where this solution could be utilized. This basically involves creating a mail script and then utilizing that properly within your notification.
Option 1: Embed an image attachment from an attachment type variable in the body of a notification:
- Create a mail script using example code:
template.print("<img src=/sys_attachment.do?sys_id=" + current.variables.name_of_attachment_variable + ">");
You can change current.variables to just current if the attachment type field is actually on your table instead of a catalog item
- Within your notification Message HTML field, you'd call the mail script for example:
Here's your embedded image: ${mail_script:name_of_mail_script}
- The final result would look something like this:
Option 2: Embed one or more image attachments that are directly attached to a record in the body of a notification:
- Create a mail script using example code:
var gr = new GlideRecord('sys_attachment'); gr.addQuery('table_sys_id', current.sys_id); gr.addQuery('content_type', "CONTAINS", "image"); //This line helps ensure you're only grabbing image type attachments gr.query(); while (gr.next()) { template.print("<img src=/sys_attachment.do?sys_id=" + gr.getValue('sys_id') + ">"); }
- Follow step 2 from Option 1, above
- The final result would look something like this:
There's always more you can do (i.e., adding height="x" and width="y" as well in the img src line to control the height and width of the image in the notification), but hopefully this helps guide you if this is something you're looking to accomplish.
Please be sure to bookmark this article as well as mark it as Helpful if you thought it was helpful.
Interested in other articles I've written? Check out this Delta Exam Guide article!
Thanks and take care! 🙂
- 4,944 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Allen Andreas
I was searching on how to show an image attachments in the body of notification and found your link.
This is exactly what I was looking. I tested and it is working wonderful for our need. However, attached images were showing a little big in the email body. I could not figure it out how to change the "Width" and "Height" of the image.
I tried this, but it is not working. Could you please help? Thank you
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I hope you have figured this out by now. I tired this and it worked. The "//682017b893300300ac0c5999357ffb2d.iix" refers to the URL for an image in the image library. I added a comma and width=xx, height=120
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks @Kyle J
My apologies @Brian186 -- I didn't see your reply originally, but the notification for Kyle's helped bring my attention here. What Kyle proposed is great and would have been what I would have suggested.
You should have access to all sorts of neat img parameters you can specify as well, more examples can be found here: https://www.w3schools.com/tags/tag_img.asp
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Kyle and Allen,
I'm really sorry for the late reply because I was on medical leave. I just got back to work yesterday. I still need your help with the attachment. I'm trying to get the image to show up in Outlook email, but it did not work. I must have done something incorrectly.
Here are the steps I have done:
1. Created Email Script:


- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Brian186
For my reply, I'd like to stay in the realm of what I posted about, meaning the code I provided. You shouldn't need to alter it too much to simple get the image width and height implemented correctly. I see you're using another users reply as your code, instead of what I offered.
Please review my code, but you can simple add height and width to it like so:
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.addQuery('content_type', "CONTAINS", "image"); //This line helps ensure you're only grabbing image type attachments
gr.query();
while (gr.next()) {
template.print('<img src=/sys_attachment.do?sys_id=' + gr.getValue("sys_id") + ' width="300" height="300">');
}
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Allen,
Thank you so much for continuing to help. After replacing the existing code with yours, I'm still struggling to get the image to show in the email. Could you please take a look at below what I have done? Hopefully, you can spot where I made a mistake and provide suggestion on fixing it.
Notification is on Approval Table


- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @Brian186
I believe originally, when you first replied, you said the attachment was showing and everything was working fine it was just that the image appeared small?
Now, you're saying the image isn't showing at all?
Please understand that this code to show the image is assuming that the image is attached to the record upon which this notification is triggered. So, is there an "image" attachment on this "sysapproval_approver" record? If not, and the image is attached on another record, such as the record that this approval is for...then you'd need to adjust the code to not use the "current.sys_id" and instead, use the sys_id of the record that this approval is for. Which might instead need to be: "current.sysapproval".
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Allen Andreas
I'm really sorry for the confusion. When I first replied, I was attaching the email script to the sc_req_item record, and it was working fine, except I needed help with sizing the image bigger. Now, management wants to see all images attached to the approval record, so I created a notification on the sysapproval_approver table and used the same email script, thinking that it should work the same as in the sc_req_item record.
You pointed out that an image needs to be attached to the record upon which this notification is triggered. It is making complete sense now. I implemented your suggested code by replacing "current.sys_id" with "current.sysaproval", and it is working perfectly.
I sincerely thank you for your time and effort.


- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content