- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on ‎04-26-2021 04:36 AM
Introduction:
I have received a business requirement, that can we add the inline report (table) instead of the excel attachments. For this, I search and start working on it, so I had few issues while working on this requirement. Hence, I have started to write this article. I think it will help community users to work on this type of requirement in the future.
Create a scheduled report which will trigger based on conditions and it will include the inline table as per business need.
Use cases:
- Create a scheduled report which will trigger based on some conditions and have reported with the inline-table format in the mail.
- Create a scheduled report with an inline table to send the assigned to users and his/her managers for pending approval of requests.
Procedure:
Step:1 Create a report and schedule it as per the required time.
Example- Create a report for example- P1/ P2 Incidents in a week.
Step:2 Scheduled the same report as per business need.
Step:3 Create a Notification email script to add report contents(records) into inline table instead of the attachments.
Here is the email scripts:
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
p1p2Incidents();
function p1p2Incidents(){
var inc = new GlideRecord(current.report.table);
inc.addEncodedQuery(current.report.filter);
inc.query();
if (inc.hasNext()) {
template.print('<br />');
template.print('<table style="height: 23px;" width="100%"><tbody><tr><td style="background-color: #0e5399;"><font color="#FFFFFF"><strong>P1/P2 Incidents:</strong></font></td></tr></tbody></table>');
var tbl = '<table style="height: 293px;" width="100%"><tbody>';
//template.print(tbl);
var tab = '<table style="width: 100%; border-collapse : collapse; " border = "2" cellpadding = "10"> <tbody>' + '<tr>' +
'<td style="background-color: #aeaeae;">' + '<b>Number</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Opened</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Priority</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Name</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Description</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Requested by</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>State</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Configuration item</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assignment group</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assigned to</b>' + '</td>' +
'</tr>';
template.print(tab);
}
while(inc.next())
{
var clsed = '<tr>' +
'<td>' + inc.number + '</td>' +
'<td>' + inc.opened_at + '</td>' +
'<td>' + inc.priority.getDisplayValue() + '</td>' +
'<td>' + inc.short_description + '</td>' +
'<td>' + inc.description + '</td>' +
'<td>' + inc.caller_id.name + '</td>' +
'<td>' + inc.state.getDisplayValue() + '</td>' +
'<td>' + inc.cmdb_ci.name + '</td>' +
'<td>' + inc.assignment_group.name + '</td>' +
'<td>' + inc.assigned_to.name + '</td>' +
'</tr>';
template.print(clsed);
}
var tab_end = '</tbody> </table>';
template.print(tab_end);
}
})(current, template, email, email_action, event);
This will add the inline table dynamically.
Step:4 Execute a scheduled report & check the mail logs.
Step:5 Check the Received email:
Conclusion:
I this way, we can add inline table in mail body with the attachments in the scheduled report. It help to improve the user experience and reduce the time to download & open the attachments to view the data.
Please do not forget to mark helpful and bookmark this article!!!!!
Thanks!
Sagar Pagar
- 4,702 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Cool, thanks for sharing this and all your scripts! I think it's a very good article. Marking it helpful.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you for publishing this article Sagar! - This is exactly what I needed.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Sagar Pagar How to Add two Reports in the Single Email script Using Your coding Method?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Sagar --You assisted me greatly with this article last year!
Is it possible to alternate the row colours on an inline table?
I have attempted to create this colouring using several different methods but have not been successful
Any help you can provide is greatly appreciated.
<nth-child: "background: "#F2F2F2 ">
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi @emaccrossan1,
Yes. It is possible to alternate the row colors on an inline table.
You need to define any temporary count variable. Inside while loop check that count is odd or event and based on it apply background colors to rows. At the end just increment the count.
Format: '<td style="background-color: #F2F2F2;" >' + objName.column_name + '</td>' +
Sample scripts:
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
p1p2Incidents();
function p1p2Incidents() {
var count = 1;
var inc = new GlideRecord(current.report.table);
inc.addEncodedQuery(current.report.filter);
inc.query();
if (inc.hasNext()) {
template.print('<br />');
template.print('<table style="height: 23px;" width="100%"><tbody><tr><td style="background-color: #0e5399;"><font color="#FFFFFF"><strong>P1/P2 Incidents:</strong></font></td></tr></tbody></table>');
var tbl = '<table style="height: 293px;" width="100%"><tbody>';
//template.print(tbl);
var headerCols = '<table style="width: 100%; border-collapse : collapse; " border = "2" cellpadding = "10"> <tbody>' + '<tr>' +
'<td style="background-color: #aeaeae;">' + '<b>Number</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Opened</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Priority</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Name</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Requested by</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>State</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Configuration item</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assignment group</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assigned to</b>' + '</td>' +
'</tr>';
template.print(headerCols);
}
while (inc.next()) {
var tableRows;
if (count % 2 == 0) {
tableRows = '<tr>' +
'<td style="background-color: #F2F2F2;" >' + inc.number + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.opened_at + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.priority.getDisplayValue() + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.short_description + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.caller_id.name + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.state.getDisplayValue() + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.cmdb_ci.name + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.assignment_group.name + '</td>' +
'<td style="background-color: #F2F2F2;" >' + inc.assigned_to.name + '</td>' +
'</tr>';
} else {
tableRows = '<tr>' +
'<td>' + inc.number + '</td>' +
'<td>' + inc.opened_at + '</td>' +
'<td>' + inc.priority.getDisplayValue() + '</td>' +
'<td>' + inc.short_description + '</td>' +
'<td>' + inc.caller_id.name + '</td>' +
'<td>' + inc.state.getDisplayValue() + '</td>' +
'<td>' + inc.cmdb_ci.name + '</td>' +
'<td>' + inc.assignment_group.name + '</td>' +
'<td>' + inc.assigned_to.name + '</td>' +
'</tr>';
}
template.print(tableRows);
count++;
}
var tab_end = '</tbody> </table>';
template.print(tab_end);
}
})(current, template, email, email_action, event);
Thanks,
Sagar Pagar
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is great! Thank you so much for your help, Sagar!
I am very grateful for this!
Have a great day!
Eamonn
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thank you so much it's worked for me
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Sagar, is it possible to add a pivot table in the body of the mail body.
That would be a very nice option...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Sagar,
Is it possible to do without attachment it should contain image only in the email body

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Thanks for this exactly wat was requested of me. Never even occurred to me to try a mail script in a scheduled report.