The CreatorCon Call for Content is officially open! Get started here.

Create a reply email via a link in a notification

Moedeb
Tera Guru

I have a notification that is going out and it has a link that opens a reply email.

When I try and "preview" the notification it looks exactly like what I want, formatted nicely, but when I actually send the notification and click the link in Outlook, the reply comes up with all the correct values in the right places, but the body text is completely unformatted and shows as just a 'blob' of text.

 

This is being done via a mail script

 

EG:

In the notification in ServiceNow I select "Preview Notification", then click on the reply email link in the notification that is previewed, and the reply email is opened in Outlook:

Moedeb_1-1749002847772.png

 

 

This is the same reply that is also opened in Outlook, but the reply email link was from the same notification, but was actually sent and received in a mailbox:

Moedeb_2-1749002914541.png

 

It looks like it is interpreting the carriage returns in the preview and not at all using them in the other one.

 

My mail script code is:

var img = "/logo.png";

var response = "reply";

var emailbod = "This is some text that I want here\r\n";
emailbod += "\r\n";
emailbod += "(Then some more text goes here)\r\n";
emailbod += "And even more here\r\n";
emailbod += "Also here\r\n";
emailbod += "Then I want a new line here and -\r\n";
emailbod += "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n";
emailbod += "also here after some space.-\r\n";

template.print(renderlogolink(img, response, emailbod));

Ideas?

I've tried html such as <br> </br> and the like and it just adds that as text to the email body, doesn't get recognised as html tags at all 

1 ACCEPTED SOLUTION

Bidduam
Tera Guru

@Moedeb give this a go:

var emailbod = encodeURIComponent("This is some text that I want here\r\n\r\n(Then some more text goes here)\r\nAnd even more here\r\nAlso here\r\nThen I want a new line here and -\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nalso here after some space.-\r\n");

 

You don't add them separately, they can all be done in the same string, but the encodeURIComponent(...) ensures special characters like line breaks (\n) are properly handled.

View solution in original post

2 REPLIES 2

Bidduam
Tera Guru

@Moedeb give this a go:

var emailbod = encodeURIComponent("This is some text that I want here\r\n\r\n(Then some more text goes here)\r\nAnd even more here\r\nAlso here\r\nThen I want a new line here and -\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nalso here after some space.-\r\n");

 

You don't add them separately, they can all be done in the same string, but the encodeURIComponent(...) ensures special characters like line breaks (\n) are properly handled.

@Bidduam that worked perfectly, thank you a heap 😁