Translated HTML fields show HTML code in email notifications

rosa8
Mega Contributor

For some reason when I include a field that is a Translated HTML field into an email notification, the HTML code prints and it looks like a mess. How do I get the data from the field to format properly? Regular HTML fields work fine.

I first noticed this when working on our kb_submission form. I'm trying to get the text to be included in the approval email notification. I'm also trying to include that same text in a notification to the Service Desk for Knowledge Articles are updated.

Thanks,
Rosa

17 REPLIES 17

cwhaley
Kilo Expert

Try using a mail script to strip out all the html content.

In the Message field on your Notification record, you would typically put something like this:


Translated Field Contents = ${u_mycustomfield}


Instead, try something like this:

<mail_script>
var cleanString = current.u_mycustomfield.toString().replace(/(<([^>]+)>)/ig,"");
template.print("Translated Field Contents = " + cleanString + "\n");
</mail_script>


This will use a regular expression pattern (/(<([^>]+)>)/ig) to find html tags and clear them by replacing them with an empty string.

Hope that helps!


rosa8
Mega Contributor

Thanks for the reply.
I tried adding the mail script and it did remove all of the html tags but all of the formatting and line breaks are now missing and it looks like a jumbled mess. So I guess I need the html formatting but I don't want the code to show.

Does this make sense?


Can you attach a screenshot?


cwhaley
Kilo Expert

Would you mind posting the message body? Here are the steps to do so:

1. Open up the the Email Log (look for "Emails" under "System Logs")
2. Locate one of the e-mails that has the extra tags (one from before the mail_script part was added)
3. Open the email
4. Find the "Body" field and copy that text
5. Come back into this form and type


<pre>
[code]<div><b>html message body</b></div>
after the message body you pasted

It should look something like this [code][code]

html message body
[/code][/code]