- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 09:16 AM
im trying to display data in table format on notification using email script but the alignment is not being properly set.
below is the script
(function runMailScript(current, template, email, email_action, event) {
var inc = new GlideRecord("incident");
inc.addEncodedQuery("state!=7");
inc.query();
template.print("<table style=\"text-align:left;background-color:F2F3F;border-collapse:collapse;font-family:arial,helvetica;font-size:12pt;padding:5px; border:1px solid;border-color:grey;\">");
template.print("<tr><td style=\"padding:5px;border:1px solid;border-color:grey;\">S.No</td>");
template.print("<td style=\"padding:5px;border:1px solid;border-color:grey;\">Caller</td>");
template.print("<td style=\"padding:5px;border:1px solid;border-color:grey;\"><strong>Short description<strong></td>");
template.print("<td style=\"padding:5px;border:1px solid;border-color:grey;\"><strong>State<strong></td></tr>");
while (inc.next()) {
var i=0
template.print("<tr><td style=\"padding:5px;border:1px solid;border-color:grey;\">");
template.print(i);
template.print("</td><td style=\"padding:5px;border:1px solid;border-color:grey;\">" + inc.caller_id.getDisplayValue() + '</td>');
template.print("<td style=\"padding:5px;border:1px solid;border-color:grey;\">" + inc.short_description + '</td>');
template.print("<td style=\"padding:5px;border:1px solid;border-color:grey;\">" + inc.state.getDisplayValue() + '</td></tr>');
}
template.print('</table>');
})(current, template, email, email_action, event);
the table is not aligned properly , and the table only applies for first record and its not applied for the second record
Solved! Go to Solution.
- Labels:
-
Notifications
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 10:24 AM
Can you try this:
(function runMailScript(current, template, email, email_action, event) {
var inc = new GlideRecord("incident");
var htmlTable = '';
inc.addEncodedQuery("state=7");
inc.query();
var i = 1;
htmlTable += "<table style='text-align:left;background-color:F2F3F;border-collapse:collapse;font-family:arial,helvetica;font-size:12pt;padding:5px; border:1px solid;border-color:grey;'>";
htmlTable += "<tr><th style='padding:5px;border:1px solid;border-color:grey;'>S.No</th>";
htmlTable += "<th style='padding:5px;border:1px solid;border-color:grey;'>Caller</th>";
htmlTable += "<th style='padding:5px;border:1px solid;border-color:grey;'><strong>Short description<strong></th>";
htmlTable += "<th style='padding:5px;border:1px solid;border-color:grey;'><strong>State<strong></th></tr>";
while (inc.next()) {
htmlTable += "<tr><td style='padding:5px;border:1px solid;border-color:grey;'>";
htmlTable += i;
htmlTable += "</td><td style='padding:5px;border:1px solid;border-color:grey;'>" + inc.caller_id.getDisplayValue() + '</td>';
htmlTable += "<td style='padding:5px;border:1px solid;border-color:grey;'>" + inc.short_description + '</td>';
htmlTable += "<td style='padding:5px;border:1px solid;border-color:grey;'>" + inc.state.getDisplayValue() + '</td></tr>';
i++;
}
htmlTable += '</table>';
template.print(htmlTable);
})(current, template, email, email_action, event);
Result:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 10:27 AM
I think my previous script works (as displayed in test result). But
So this will work without the strong tags:
(function runMailScript(current, template, email, email_action, event) {
var inc = new GlideRecord("incident");
var htmlTable = '';
inc.addEncodedQuery("state=7");
inc.query();
var i = 1;
htmlTable += "<table style='text-align:left;background-color:F2F3F;border-collapse:collapse;font-family:arial,helvetica;font-size:12pt;padding:5px; border:1px solid;border-color:grey;'>";
htmlTable += "<tr><th style='padding:5px;border:1px solid;border-color:grey;'>S.No</th>";
htmlTable += "<th style='padding:5px;border:1px solid;border-color:grey;'>Caller</th>";
htmlTable += "<th style='padding:5px;border:1px solid;border-color:grey;'>Short description</th>";
htmlTable += "<th style='padding:5px;border:1px solid;border-color:grey;'>State</th></tr>";
while (inc.next()) {
htmlTable += "<tr><td style='padding:5px;border:1px solid;border-color:grey;'>";
htmlTable += i;
htmlTable += "</td><td style='padding:5px;border:1px solid;border-color:grey;'>" + inc.caller_id.getDisplayValue() + '</td>';
htmlTable += "<td style='padding:5px;border:1px solid;border-color:grey;'>" + inc.short_description + '</td>';
htmlTable += "<td style='padding:5px;border:1px solid;border-color:grey;'>" + inc.state.getDisplayValue() + '</td></tr>';
i++;
}
htmlTable += '</table>';
template.print(htmlTable);
})(current, template, email, email_action, event);