Script rows & columns in an Email Script

nebula
Tera Guru

Following this resolution, I am creating an email script that lists our CI's and owners in rows and columns. I am able to generate the column, but one side (owners) is significantly shorter. The formatting is making this a big challenge as it does display the information, just not well. I believe an issue could be that I didn't close the </width> but even adding it to line 12 in the screen shot didn't seem to keep the width of the rows short. 

 

Thank you for reading!

1 ACCEPTED SOLUTION

Try this

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    template.print("<head><style>td{ word-break: break-all;}table{width:100%;border-collapse:collapse;text-align:left;} th{border:1px solid black;}, td</style></head>");
    template.print("<table style = 'font-family: arial;  font-size: 12px;'><tr><th>Affected CI</th><th>Owned By</th></tr>");

    var gr = new GlideRecord('task_cmdb_ci_service');
    gr.addQuery('task', current.sys_id);
    gr.addNotNullQuery('cmdb_ci_service.owned_by');
    gr.query();
    //template.print("</tr>");
   // template.print("</td>");
    while (gr.next()) {
        template.print("<tr><td style=\"border: 1px solid;border-color: black;border-collapse:collapse;\" >");
        template.print(gr.cmdb_ci_service.name + "</td>");
        template.print("<r><td style=\"border: 1px solid; border-color: black;border-collapse:collapse;\" >");
        template.print(gr.cmdb_ci_service.owned_by.name + "</td>");
        template.print("</tr>");
    }
    template.print("</table>");

})(current, template, email, email_action, event);

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

View solution in original post

6 REPLIES 6

Try this

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    template.print("<head><style>td{ word-break: break-all;}table{width:100%;border-collapse:collapse;text-align:left;} th{border:1px solid black;}, td</style></head>");
    template.print("<table style = 'font-family: arial;  font-size: 12px;'><tr><th>Affected CI</th><th>Owned By</th></tr>");

    var gr = new GlideRecord('task_cmdb_ci_service');
    gr.addQuery('task', current.sys_id);
    gr.addNotNullQuery('cmdb_ci_service.owned_by');
    gr.query();
    //template.print("</tr>");
   // template.print("</td>");
    while (gr.next()) {
        template.print("<tr><td style=\"border: 1px solid;border-color: black;border-collapse:collapse;\" >");
        template.print(gr.cmdb_ci_service.name + "</td>");
        template.print("<r><td style=\"border: 1px solid; border-color: black;border-collapse:collapse;\" >");
        template.print(gr.cmdb_ci_service.owned_by.name + "</td>");
        template.print("</tr>");
    }
    template.print("</table>");

})(current, template, email, email_action, event);

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Rohila V
2022-25 ServiceNow Community MVP

It's perfect!! I did change the width from 100% to 50% but it's exactly what I wanted! Thanks!!!