How to align table in email script ?

Community Alums
Not applicable

Hi everyone,

I want to align table in email script with header and values for certain field.
I have written email script, I am getting data but alignment is not proper. could anyone give a solution.
email script:

For Header

if (tableName == "cmdb_ci_service_discovered") {
template.print("<style>table{width:100%;border-collapse:collapse;} th{border:1px solid black;font-family:Arial;font-size:11pt;padding:20px;}, td</style><table><tr><th width=20%>Application Service Number</th><th width=20%>Name</th><th width=20%>Accountable Owner</th><th width=20%>Managed by</th><th width=20%>Accountable Remediation Owner</th><th width=20%>ARO Backup</th><th width=20%>ARO governance</th></tr></table>");

 

For values:

if (tableName == "cmdb_ci_service_discovered") {
template.print("<html><style>table{font-family: arial, sans-serif;border collapse: collapse;width: 100%;}td,th{border: 1px solid;text-align: left;padding: 8px;}</style><body><table><tr><td width=20%> " + gr.number + " </td><td width=20%> " + gr.name + " </td><td width=20%> " + gr.assigned_to.getDisplayValue() + " </td><td width=20%> " + gr.managed_by.getDisplayValue() + " </td><td width=20%> " + gr.u_accountable_remediation_owner.getDisplayValue() + " </td><td width=20%> " + gr.u_aro_backup.getDisplayValue() + "</td><td width=20%> " + gr.u_aro_governance.getDisplayValue() +
" </td></tr></table></body></html>");

Venugopalsr_0-1675946004390.png

 


Thanks

2 REPLIES 2

Mary Vanatta1
ServiceNow Employee
ServiceNow Employee

Have you thought that just adding the fields and not using a table might look cleaner and more simple to execute? 

Email Notification Header
Application Service Number: 
Name:
Accountable Owner:
Managed by:
Accountable Remediation Owner:

ARO Backup:
ARO Governance:


-O-
Kilo Patron
Kilo Patron

You are adding as many tables as records + 1. While it would be possible to make all of those the same width, it is next to impossible to make columns within those the same with.

But the solution is simple: add just one table.