Mail script alignment

Prem13
Tera Contributor

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

1 ACCEPTED SOLUTION

Willem
Giga Sage
Giga Sage

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:

find_real_file.png

View solution in original post

5 REPLIES 5

Willem
Giga Sage
Giga Sage

I think my previous script works (as displayed in test result). But @Maik Skoddow  pointed to the strong. That is not needed in the script I provided since we use the th to declare the headers.

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);