- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 03:47 PM
Hi community,
I'm trying to create an email script that takes records received from a GlideRecord and shows a couple fields from the record in an email. I can get the info, but formatting script so it looks right is proving to be challenging. Here's my script:
and here's what it looks like in the email
what i want is a nice table look with columns that have "Number", "State", and "Summary" going horizontal, with the appropriate values shown beneath...kind of like a spreadsheet view, or even a typical ServiceNow list view.
any help would be great...thanks!
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-14-2018 07:54 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 04:58 PM
You'd need to structure it a little differently to print the html table. Here's some psuedo code:
<table><tr><td>Number</td><td>State</td><td>Summary</td></tr>
open while loop
tr
print td task number /td
print td etc /td
etc.
/tr
end while loop
/table

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-03-2018 05:00 PM
You're looking to implement HTML Tables: https://www.w3schools.com/html/html_tables.asp
You will want to create one table with a table header and a couple rows. Here's the HTML for that:
<table>
<tr>
<th>Number</th>
<th>State</th>
<th>Summary</th>
</tr>
<tr>
<td>gr.task.number</td>
<td>gr.task.state</td>
<td>gr.task.short_description</td>
</tr>
</table>
You then need to incorporate that into your template.print() statements like you're already doing.
If you want to add borders and row highlighting, check out the reference link for some examples. You may also want to look into making the table width 100% or some set value to make it cleaner. I would recommend looking at some of the ways ServiceNow implements this in baseline code as well (suiteCompletion.email notification email script for example).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2018 01:18 PM
Hi,
Though my reply is a little messy, I believe this is what you are looking for. You may need to adjust the styles.
For Table Heading:
template.print("<style>table{width:100%;border-collapse:collapse;} th{border:1px solid black;font-family:Arial;font-size:11pt;padding:10px;}, td</style><table><tr><th width=20%>Number</th><th width=20%>State</th><th width=60%>Summary</th></tr></table>");
For Table Rows and Data:
To be written after writing GlideRecord.
template.print("<html><style>table{width:100%;} td{border:1px solid black;padding:10px;font-family:Arial;font-size:10pt;border-top:0px;}</style><table><tr><td width=20%>gr.task.number</td><td width=20%>gr.task.u_state</td><td width=60%>gr.task.short_description</td></tr></table></html>");
Hope this helps.
Mark the answer as Correct/Helpful based on its impact.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2023 12:45 AM
this was quickly helpful and helped me smoothly chowk out table , still headings and data needed some alignment as you mentioned to adjust so i added this piece
table{width:100%;border-collapse:collapse;table-layout: fixed;}
and
td{border:1px solid black;font-family:Arial;font-size:11pt;padding:10px;word-wrap: break-word;}
this fixed its alignment also
once again thanks Archana for quick help