- 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-16-2022 09:13 PM
Try this in email script.
template.print('<style>th {background-color: #404040; color: white;} table,th,td{text-align: center; border: 1px solid black; border-color: #404040; border-collapse: collapse;} </style><table style="width:100%";><tr><th>Number</th><th>Short Description</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.price + '</td></tr>');
total += parseFloat(gr.price);
}
template.print('<tr><td style="border: none"/><td style="border: none"/><td>' + total + '</td></tr>');
template.print('</table>');
}
Output would look something like below.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 09:25 PM
Thank you Muhammad, do you know how i can add another column after Short Description and before Price? also how can i spread it out to occupy the entire space, as the data looks compressed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-16-2022 10:07 PM
Try with below script.
(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: #404040; color: white;} table,th,td{text-align: center; border: 1px solid black; border-color: #404040; border-collapse: collapse;} </style><table style="width:200%";><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 style="border: none"/><td style="border: none"/><td style="border: none"/><td>' + total + '</td></tr>');
template.print('</table>');
}
})(current, template, email, email_action, event);
- 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