Scheduling a report with inline table instead of the attachments
Scheduling a report with inline table instead of the attachments
Introduction:
I have received a one business requirement, that we can add the inline report (table) instead of the excel attachments. For this I searched and started 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 future.
Create a scheduled report which will trigger based on conditions and it will include the inline table as per business need.
Use case’s:
Create a scheduled report which will trigger based on some conditions and have inline report in 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:
Create a report and schedule it as per the required time.
Example- Create a report for example- List of CRs for CAB Meeting.
Scheduled the same report as per business need.
Create a Notification email script to add report contents(records) into inline table instead of the attachments.
Here is the script: Step 5:
It will add the inline table in dynamically.
Execute a scheduled report & check the mail logs.
Received email:
Conclusion:
I this way, we can add inline table instead of the attachments in scheduled report.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
changeRequest();
function changeRequest(){
var chg = new GlideRecord(current.report.table);
chg.addEncodedQuery(current.report.filter);
chg.query();
if (chg.hasNext()) {
template.print('<br />');
template.print('<table style="height: 23px;" width="100%"><tbody><tr><td style="background-color: #0e5399;"><font color="#FFFFFF"><strong>Blackout Window - ECR\'s Approved by Praveen & Anoop</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>Name</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Category</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>Configuration item</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assignment group</b>' + '</td>' +
'<td style="background-color: #aeaeae;">' + '<b>Assigned to</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Business Impact</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Reason</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Business Impact</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Root Cause</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Fix Required</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Change Scope</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>State</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Active</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Updated</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Updated by</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Reason</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>CCB date</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Type</b>' + '</td>' +
// '<td style="background-color: #aeaeae;">' + '<b>Conflict status</b>' + '</td>' +
'</tr>';
template.print(tab);
}
while(chg.next())
{
var clsed = '<tr>' +
'<td>' + chg.number + '</td>' +
'<td>' + chg.opened_at + '</td>' +
'<td>' + chg.short_description + '</td>' +
'<td>' + chg.category + '</td>' +
'<td>' + chg.description + '</td>' +
'<td>' + chg.requested_by.name + '</td>' +
'<td>' + chg.cmdb_ci.name + '</td>' +
'<td>' + chg.assignment_group.name + '</td>' +
'<td>' + chg.assigned_to.name + '</td>' +
// '<td>' + chg.u_business_impact + '</td>' +
// '<td>' + chg.u_root_cause + '</td>' +
// '<td>' + chg.u_fix_required + '</td>' +
// '<td>' + chg.u_change_scope + '</td>' +
// '<td>' + chg.conflict_status + '</td>' +
// '<td>' + chg.type + '</td>' +
// '<td>' + chg.cmdb_ci + '</td>' +
// '<td>' + chg.reason + '</td>' +
// '<td>' + chg.state + '</td>' +
// '<td>' + chg.active + '</td>' +
// '<td>' + chg.sys_updated_on + '</td>' +
// '<td>' + chg.sys_updated_by + '</td>' +
'</tr>';
template.print(clsed);
}
var tab_end = '</tbody> </table>';
template.print(tab_end);
}
})(current, template, email, email_action, event);
Comments
Post a Comment