- 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 09:29 AM
Hi Prem,
I'm afraid it is not clear, what your question is.
The only thing I can say is, that
- variable i is not incremented and therefore always remains 0,
- table alignment is better solved with HTML attributes: <table align="center">
- text formatting should be better done within a sourrounding <div> or in each cell but not at <table>
- there are to many unnecessary escapings, which increase risk of erros. Better write
template.print('<td style="padding:5px;border:1px solid;border-color:grey;"><strong>State<strong></td></tr>');
Kind regards
Maik
If my answer replied your question please mark appropriate response as correct so that the question will appear as resolved for other users who may have a similar question in the future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 09:46 AM
Hi Maik,
Actually the values are not properly aligned , i dont see any issues with the script.
i made some minor tweaks as you suggested still the same.
(function runMailScript(current, template, email, email_action, event) {
var inc = new GlideRecord("incident");
inc.addEncodedQuery("state=7");
inc.query();
var i=1;
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()) {
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>');
i=i+1;
}
template.print('</table>');
})(current, template, email, email_action, event);
output:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2021 10:24 AM
Hi,
I think I found the problem. In your table header row two times a unclosed <strong> tag is defined.
Please make sure that all opened tags are closed later.
<strong>Short description</strong>
Kind regards
Maik
- 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: