How do I script creating a table in a mail script?

Stacy1
Mega Guru

We would like to script the creation of a table in a mail script.  The reason I want to script it is I only want to add a row if there is a value for that particular variable.

The table should look something like this.  (If there is no Module then that row should not show up, etc.)

Thanks,

Stacy

Priority: current.priority
Product: current.product
Module: current.module
Activity: current.activity (if there was no data for this row I don't want this row to show)
Description: current.description
1 ACCEPTED SOLUTION

Stacy1
Mega Guru

I ended up not setting the font at all in my email script.

Instead I used a email layout and set the font there and called it in my email template.

Worked perfect.

View solution in original post

13 REPLIES 13

sachin_namjoshi
Kilo Patron
Kilo Patron

Use below solution to create table in email script.

You will have to do Glide query to see if value is available and then show record.

 

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



template.print('<table border="1px solid black">');

template.print( "<tr bgcolor='#ddd' align='center'>" );
template.print("<td style='text-align:center' colspan='3'><strong>Heading</strong></td>");
template.print( "</tr>" );

template.print( "<tr>" );
template.print( "<td><left><b>" + "first name" + "</b></left></td>" );
template.print( "<td><left><b> Middle name </b></left></td>" );
template.print( "<td><left><b> last name </b></left></td>" );
template.print( "</tr>" );

template.print( "<tr>" );
template.print( "<td><left>" + "field1" + "</left></td>" );
template.print( "<td><left> field2 </b></left></td>" );
template.print( "<td><left> fiedl3 </left></td>" );

template.print( "</tr>" );
template.print('</table>');



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

Regards,

Sachin

asifnoor
Kilo Patron

Try this code.

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

template.print("<table>");
if(current.priority!='') {
  template.print("<tr><td>Priority:</td><td>"+current.priority.toString()+"</td></tr>");
}
if(current.product!='') {
  template.print("<tr><td>Product:</td><td>"+current.product.toString()+"</td></tr>");
}
//Follow same procedure for others
template.print("</table>");


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

Mark the comment as a correct answer and also helpful if it helps.

This is working great.  However, I want to specify the font for the hard coded words and the variables data coming in.  I can get it to work for everything but the table.  Do I need to put the font someplace else in the code? I tried adding it in my html variable but I get errors when trying to enter it there.

find_real_file.png

Thanks,

Stacy

You can use html to change to font using <font> tag

https://www.w3schools.com/tags/tag_font.asp

 

Below is the example

 

template.print('<p><font size="3" face="arial">');

 

Regards,

Sachin