Sending Reports in the mail body
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2018 05:37 AM
I have created a Report and my requirement is to schedule that report and send as a mail to users.
I was able to send as an attachment, but my requirement is to send that report content in the email body as a screenshot or it can be of anything. But the report contents should be displayed in the email body
Please help in achieving this.
Regards
Adarsh
- Labels:
-
Reporting

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-19-2018 06:31 AM
You can create mail script and add it to notification body like ${reportToHtml}.
reportToHtml();
function reportToHtml () {
var html = "<html>";
html += "<head>";
html += "<style>table {width:100%; text-align:center;}, td{text-align:right;}, th{border:0px solid black;background-color: #d6d6d6;}th{background-color: #49aaff;color:white;}table.alternate tr:nth-child(odd) {background-color: #D8D8D8;} table.alternate tr:nth-child(even) {background-color: #F2F2F2;}</style>";
html += "</head>";
html += "<body>";
//Get the Report
var gr = new GlideRecord("sys_report");
gr.get(event.parm1);
email.setSubject(gr.title);
html += '<strong style="text-align: center;">';
html += gr.title;
html += ":</strong>";
//html += '<table border="0">';
html += '<table border="0" class="alternate" style="width: 100%;text-align: center;">';
//Begin Table//
html += '<tr style="background-color: #D8D8D8">';
var fieldList = gr.getValue('field_list').split(",");
for (var i = fieldList.length - 1; i >= 0; i--) {
html += '<th style="background-color: #49aaff;color: white"><b>';
var dictionaryQuery = new GlideRecord(gr.getValue("table"));
dictionaryQuery.addEncodedQuery(gr.getValue("filter"));
dictionaryQuery.query();
if (dictionaryQuery.next()) {
html += dictionaryQuery.getElement(fieldList[i]).getLabel();
}
html += "</b></th>";
}
html += "</tr>";
var counter = 0;
var taskQuery = new GlideRecord(gr.getValue("table"));
taskQuery.addEncodedQuery(gr.getValue("filter"));
taskQuery.query();
while (taskQuery.next()) {
counter ++;
if(counter % 2 == 0){
html += '<tr style="background-color: #F2F2F2">';
}else{
html += '<tr style="background-color: #D8D8D8">';
}
for (var a = fieldList.length - 1; a >= 0; a--) {
html += '<td>';
if(taskQuery.getElement(fieldList[a]).getED().getInternalType() == 'reference'){
html += '<a href="';
html += gs.getProperty('glide.servlet.uri');
html += taskQuery.getElement(fieldList[a]).getRefRecord().getLink(true);
html += '">';
html += taskQuery.getElement(fieldList[a]).getDisplayValue();
html += "</a>";
}else{
html += taskQuery.getElement(fieldList[a]).getDisplayValue();
}
html += '</td>';
}
html += '</tr>';
}
html += "</table>";
html += "</body>";
html += "</html>";
template.print(html);
}
Schedule event to be fired in scheduled job (sys_auto) make sure to add sys_id of report
gs.eventQueue("report.sla.nearing", current, 'sysid of report xxxxxxxx', null);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2020 05:03 AM
Hi Mike,
I tried this and the data is printing on the body of email.
But the columns are printing from last to first position.
How to make (eg:change) number as link.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-14-2020 05:24 AM
Hi Adarsh,
This may help you :
Let me know, if that answers your question and mark my answer as correct / helpful
Regards,
Mohammad Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-17-2020 09:35 PM
Hey Adarsh,
Is this answered?
If Yes, can you please mark response as correct so others will refer same in future and this will remove from unresolved thread.
Regards,
Mohammad Danish