- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 10-01-2019 04:49 PM
To save time, users want to open an email on their phone and quickly see if they need to look more at an issue or if they can move on.
By default, ServiceNow attaches reports (whether sent as a PDF or PNG) to emails when emailing a scheduled report which requires the recipient to open the email, then open the attachment. This does not always meet our users’ expectations.
With the power of the NOW Platform, we can apply a small customization to embed graphical reports as images in your emails to deliver emails like this to your users:
Create Business Rule to embed images
Create a new business rule on sys_email to modify the content of emails to embed the images before the record is first inserted.
Fill out the form with the following values:
Name: Inline Report Images
Table: Email [sys_email]
When to run
When: before
Insert: checked
Filter Conditions
Target table [is] sysauto_report
Advanced
Script:
(function executeRule(current, previous /*null when async*/) {
// check if tag is found in body
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_email_attachment');
attach.addQuery('email', '=', current.sys_id);
attach.addQuery('attachment.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)
{
gs.warn('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 id="img_' + attach.attachment + '" alt="' + attach.attachment.getDisplayValue() + '" src="sys_attachment.do?sys_id=' + attach.attachment + '"/>';
}
// 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);
return;
})(current, previous);
On a scheduled report, specify where to put the images
Placing the string “[embedded report]” in the Introductory message. It is recommended to make this text a link back to the desired report or dashboard to drive engagement with the live data in the source instance.
Only image files (PNG) reports are in-lined in the email text. Other files (PDF or Excel) will be attached to the email.
If multiple reports are sent at the same time (with the “Include with” option), all the images will be included in the email, however, the order of the images is not guaranteed.
Additional Documentation
Schedule a report - https://docs.servicenow.com/bundle/newyork-platform-administration/page/administer/reference-pages/t...
Automate report distribution - https://docs.servicenow.com/bundle/newyork-performance-analytics-and-reporting/page/use/reporting/ta...
Create a business rule - https://docs.servicenow.com/bundle/newyork-application-development/page/script/business-rules/task/t...
- 22,089 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is pretty cool!
I feel that P.A. is still behind on exporting options compared to e.g. Power BI, so it's always nice to find improvements 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi All,
I'm on London version, I did the Business Rule by following the provided instructions and scheduled the report but no image are displayed directly in the Email Body but just attached.
Can you please help me to have it works?
Are there steps omitted in the guide?
Many thanks in advance for any kind of support you can provide
Dario
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I'm not aware of any changes between London and New York that would affect this. Double-check you have everything enabled here that is described (add the BR and set the report to be a PNG). If that isn't working, add some debug statements (gs.info()) to the BR and make sure it is firing as expected.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
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);
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi
I have tried the code given here. In the email body received, the image of the report is shown as, 'undefined' with the broken icon of an image. Please advise.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
You would have to look at the logs to see what is going on. Are you running New York?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for the update Adam. I am in Mandrid.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
We are seeing this as well currently we're looking at logs but not seeing anything to point us in the right direction.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Are you on Madrid or New York? This was only tested on New York. I'm not sure what changes need to be made to get this to work prior to New York.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I got this to work using an adjustment to Kristoff's code.
The biggest difference is how the image tag is constructed, specifically how the src is built and passing in the sys_id.
Here is my complete solution:
(function executeRule(current, previous /*null when async*/) {
// check if tag is found in body
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('attachment.content_type', 'STARTSWITH','image/'); // only images supported
attach.addQuery('content_type', 'STARTSWITH','image/'); // only images supported
attach.addQuery('email', '=', current.sys_id);
//attach.addQuery('sys_id', 'sys_id');
// 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)
{
gs.warn('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 id="img_{id}" alt="{alt}" src="sys_attachment.do?sys_id={sid}"'
.replace('{id}', attach.file_name)
.replace('{alt}', attach.file_name)
.replace('{sid}', attach.sys_id);
}
// 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);
return;
})(current, previous);
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks Adam and Arkanslan. That helped me. One more query, do we need to do any changes in business rule, if we need to include multiple reports in the same mail body using the 'Include with' option.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I believe it works with multiple because this is working on the email that is generated which would have all the images attached.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Adam,
I tried to include two reports with graphs to be included in the mail body. I have added a report to the 'Include With' option. But only the second report's image is included in the mail body. Both the report's graph are attached in the mail. Any valuable suggestions will be helpful.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Are you running New York? I didn't test it on prior versions.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I am on Mandrid
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Adam,
I have tried the same in New york and it is working fine. Thanks
Does anyone has any inputs for including multiple images in the same mail body in Madrid version.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Adam,
I've set this up as specified above and it is working as expected with one exception. the [embedded report] link does not seem to be functioning. I cannot click the image to launch the report in my browser. currently on Orlando
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Did you make it a link in the template? There is nothing special about it (and it is not dynamic), you should just be able to create the link to the desired report (or dashboard).
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
it is a link in the scheduled report.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
In Paris release.....there is a new type of PNG that allows users to see the bar or pie chart images
If the report output type is Embedded PNG,
- Use the tag
${report:png}
in the message body to position the report at a specific place in the message. Otherwise, the report is placed at the bottom of the message. - Use the tag
${report:include_with}
to position other reports included with the email. Otherwise, these reports are placed at the bottom of the message.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Maggieo,
I'm using Paris version, tried to set schedule report with the new Embedded PNG type, but it not working as expected.
Did you mange to get it working?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Great point, once you are on Paris, you should use the new out of the box functionality and remove this customization.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Seem like the new feature in Paris isn't working as expected..
Any ideas?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
If it isn't working for you, I would put in a case on HI.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
When I look in the sys log and the email, I see the image . But when I send the email , I only see the image icon. I think it's some settings in outlook that prevents the image to be displayed. I'm still investigating
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I really believe it's some settings in email programs. I sent the scheduled embedded png to my home address (oneandone webmail) and opened on my Amazon Fire, it displayed the images beautifully. Google email didn't work and my company outlook email doesn't work either.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Did you find the root cause or solution? I am having the same problem. I'm unable to find other community posts or KB articles about this issue, too.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Add me to the list of people having the same issue with the Paris option. Anyone find a solution yet?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Paris Patch 8 has identified the root cause and has a link to this KB0957897. The article refers to this forum and recommends using a script that is posted here.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Adam,
We have requirement to display PNG image of report in body of the schedule mail alo with attach PDF.
Currentlt if we select "Type as PNG" is attaching PNG file. Could you please suggest me this requirement is possible or not
PNG in email Body and PDF in mail attachment for same schedule report.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Are you using the OOTB functionality for the attachment or the above script? The script above should have it embedded and as an attachment.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes I am using above script.The attachment is also PNG.
I want attachment as PDF and PNG should display in body of mail.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Yes using above script its only displaying PNG image in email body.
But My requirement both attachment and display image.
Even i want attachment as PDF and also display image in email body
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
We have a requirement to embed indicator charts in an email. Is it possible that using above script can help us achieve this with scheduled indicator?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I certainly agree.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello,
Do you know how I can resolve this error?
Root cause of JavaScriptException: com.glide.script.fencing.access.ScopeAccessNotGrantedException
: com.glide.script.fencing.access.ScopeAccessNotGrantedException: read access to sys_email_attachment not granted
Thank you.
-- Nevermind, I was able to add Cross scope privileges and the image is now embedded in my email. Thank you for this solution!

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
With Utah out is this still the way to embed reports in email?
Has anyone used OAM (outlook actionable messages) for something like this? Would it provide the capabiliy?
Thanks! Russ
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Adam Stout I used your article when worked, thank you,
But I have a doubt, is possible to resize the image in my email? Because when I receive the e-mail, the image is too big and need to reduce the size.
Thanks in advance.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
I have not tested this, but I would imagine putting in a CSS attribute in the <img> tag would do it. Perhaps try max-width.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Adam Stout I tried two ways
<p><img src="${report:png}" width="150" height="150" /></p>
and also
<p><img ${report:png}" width="150" height="150" /></p>
But both didnt work, please do you know what can I do?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @MR Carvalho im also looking to resize the image. Did you found anything that works. If yes pls suggest
@Adam Stout any help on this is ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello there
I have a question regarding the Embedded PNG in the scheduled emails.
I have several reports with a chart and I am sending them all in one scheduled email. I am able to place five PNG charts into the email body using the Included in Email related list and Include with field and it works fine.
I am using the ${report:include_with} to place the PNG files into the email body.
It works but does not look good. Charts are too large and they are placed under each other so the email is too long ...
So my question is: Is there any way to format this embedded PNG files from multiple scheduled report sources? To change its size, order etc...
Thank you
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is there anyway to put a dashboard tab into an email and then when they click on it - it launches the Dashboard?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello @Glen Schultz
this might not help you but just in case.
On dashboard there is Export to PDF UI action
and here you have these options:
But what I ended up doing is the following:
I created a scheduled report containing one of the reports from the dashboard. Type of the Scheduled Report is Embedded PNG.
In the "Included in Email" related links I added/created more Scheduled reports, all of it as Embedded PNG and added more reports from the dashboard.
Also I created an Email script which contains the sys_property (which I created) with the link to the dashboard and added this email script into the dashboard. You can set one of the embedded PNGs as a link to the dashboard.
Hope it helps a bit...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks @Mira1992 - I tried the export to PDF but it cuts off the report and doesn't work for what we need.
As for the other item - I found "Included in Email"and will try that but it is only other scheduled reports vs reports. There is not a choice for Embedded PNG for type of schedule report.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Do you know if anyone was able to get the image resizing working?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This works fine for me, but our company don't want business rules to be created due to performance issues. So is there any other way that i can try. Please suggest.