- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 07:47 PM - edited 11-16-2022 07:48 PM
Hi All!
We have a requirement to add a table in Email notification that will list all Order records(sample table). I have created a mail script that is called in the Notification body. Please see below Body for the sample created in Incident. This seems to be okay but it needs to be center aligned, with border and have to add a Grand total computation at the bottom right. Please help me update this, below is the script used:
It should be in this format + border
Mail Script
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
template.print('<table style="width:100%">');
template.print('<tr><th>Number</th><th>Short Description</th><th>State</th><th>Severity</th></tr>');
var gr = new GlideRecord("incident");
gr.addEncodedQuery("active=true^short_descriptionSTARTSWITHtester");
gr.query();
if (gr.getRowCount() > 0) {
while (gr.next()) {
template.print('<tr><td>' + gr.number + '</td><td>' + gr.short_description + '</td><td>' + gr.state + '</td><td>' + gr.severity + '</td></tr>');
}
template.print('</table>');
}
})(current, template, email, email_action, event);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2022 10:24 PM
This one looks better.
(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */
email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */
event) {
// Add your code here
template.print('<style> th{background-color: #04AA6D; color: white;} th,td{text-align: center; padding: 8px;} tr:nth-child(even){background-color: #f2f2f2;} tr:hover{background-color: #ddd;} </style><table style="font-family: Arial; border-collapse: collapse; width: 100%;"><tr><th>Number</th><th>Short Description</th><th>State</th><th>Price</th></tr>');
var total = 0;
var gr = new GlideRecord("sc_req_item");
gr.addActiveQuery();
gr.orderBy('number');
gr.query();
if (gr.hasNext()) {
while (gr.next()) {
template.print('<tr><td>' + gr.number + '</td><td>' + gr.short_description + '<td>' + gr.state.getDisplayValue() + '<td>' + '$' + gr.price + '</td></tr>');
total += parseFloat(gr.price);
}
template.print('<tr><td/><td/><td><td>' + total + '</td></tr>');
template.print('</table>');
}
})(current, template, email, email_action, event);
Output
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-17-2022 01:55 AM
Thank you, Muhammad! I appreciate your help! 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2022 05:27 PM - edited 12-14-2022 05:51 PM
Hi @Muhammad Khan, this script has been working thank you so much,
Would you be able to help me again in the Column alignment, i have a requirement to update this
Left Align: Resource Type, Vendor, Short Description
Right Align: Total and the grand total the "13099.33" text below.
Thank you!
Current script:
var approvalFor = current.sysapproval.getRefRecord();
var proj;
var query;
var dmnd = new GlideRecord('dmn_demand');
dmnd.addQuery("sys_id", current.sysapproval);
dmnd.query();
if (dmnd.next()) {
proj = dmnd.project;
}
template.print('<style>th table,th,td{text-align: left; border-color: #404040; border-collapse: collapse;} </style><table style="width:90%";><tr><th>Resource Type</th><th>Vendor</th><th>Short Description</th><th>Total</th></tr>');
var total = 0;
var cost_plan = new GlideRecord('cost_plan');
cost_plan.addQuery("task", proj);
cost_plan.query();
if (cost_plan.hasNext()) {
while (cost_plan.next()) {
template.print('<tr><td>' + cost_plan.resource_type.getDisplayValue() + '</td><td>' + cost_plan.u_vendor.getDisplayValue() + '<td>' + cost_plan.name + '<td>' + cost_plan.cost_local_currency + '</td></tr>');
total += parseFloat(cost_plan.cost_local_currency);
}
template.print('<tr><td style="border: none"/><td style="border: none"/><td style="border: none"/><td>' + total + '</td></tr>');
template.print('</table>');
}