How to clearly format HTM and Text email data

wakespirit
Kilo Guru

Dear all,

I am creating through a notification email script an email content which is collecting record data and display them in a nice HTML table.

This works nicely when email is read correctly in html.

Now in email form we can also define content for text email format.

Based on my notification email scripting, does it means I need to have 2 different script wich handle HTML and Text rendering ?

regards

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

Does the response to this question answer this as well?

https://community.servicenow.com/community?id=community_question&sys_id=2e8e17afdbf12f001089e15b8a96194f

Simon Christens
Kilo Sage

Servers are not that good at stripping HTML tags as a browser. - You risk removing valid text if you edit it serverside.

Client side you can use the below to format HTML text to plain text:

var html = g_form.getValue('u_html_description');
var div = document.createElement("div");
div.innerHTML = html;
var text = div.textContent || div.innerText || "";

//Sets plain text into description
g_form.setValue('u_text_description', text);

Just be aware that in London you need to check "Isolate script" in order to use "document" (DOM elements)

 

My html rendering works nicely.

My question was more on the pure text email format

Do I have to create 2 different email script for HTML and Text rendering format ?

kshitiz2
Kilo Contributor

Hi Scal,

I don't think so that you need to create 2 different email script for HTML and Text format. 

 

Try doing it from the "HTML Source" for the email message body in the Notification.

And for the Notification email script you can mention like:

for Example:

var cmnt2 = notes.split('(Additional comments)');
gs.log(cmnt2, 'Notify');
template.print('<span style="font-size:10pt; font-family: arial, helvetica, sans-serif;margin-top:-.01cm;">(<strong>'+ cmnt2[0].trim() + '</strong>) <br>');
template.print(cmnt2[1] + '</span>');
}

 

Kshitiz