
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2020 12:35 PM
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 |
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 02:43 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2020 12:42 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-16-2020 12:54 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 08:31 AM
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.
Thanks,
Stacy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-19-2020 08:36 AM
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