How to set the records in table format

Sathwik1
Tera Expert

In continuation to this question  

https://community.servicenow.com/community?id=community_question&sys_id=7e3e79861be2cd50d018c8ca234bcb9c

I am getting output as "INC0000001RITM0010001"

but I am excepting output as..{table format}

  Number  
INC0000001
RITM0010001

@shloke04 can you please help?

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi @Sathwik 

As discussed in your last post , if you want to have it as a Tabular format then please update your last code which I helped you out with below code.

This will give you the details in Tabular Format

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

    // Add your code here
    var getArray = event.parm1.toString();
    var splitStr = getArray.split(',');
    template.print('<table border="1">');
    for (var i = 0; i < splitStr.length; i++) {
        template.print("<tr>");
        template.print("<td>" + 'Number' + "</td>");
        template.print("<td>" + splitStr[i] + "</td>");
        template.print("</tr>");
    }
    template.print("</table>");

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

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

5 REPLIES 5

Jan Cernocky
Tera Guru

Hi Sathwik,

I guess your output is a string separated by comma, right?

Simply run replaceAll function and replace a space with \n

var output = 'abc efg';
gs.info(output);
var output2 = output.replaceAll(' ', '\n');
gs.info(output2);

Note: in case the email is in HTML format you may need to replace it with <BR> not \n to break the line in HTML

Hi, Task for your response..here my requirement is not to get in a new line. I need in table format.. In Table header I need Number In Row 1 need 1st value before comma INC00020 In Row 2 need 2nd value after comma RITM08633 and so on if more records.. Got it?

Hey,

are you referring to an HTML table with all the <td> and <tr> tags? Alternatively <div> tags?

If you need just a simple text formatted to look like a table, you can do what I suggested earlier. To get the header, just add whatever you need at the beginning with comma by using concat (don't forget to keep one extra space in the header so it is also replaced with new line tag):

var output = 'INC0000001 RITM0010001';
var header = 'Number ';

var output2 = header.concat(output).replaceAll(' ', '\n');;

gs.info(output2);

And the output will be like this (without the *** script: part)

find_real_file.png

Thanks for your help.. Can you please guide me on how to write all these in notification / email script