Carriage Returns (or line breaks) for Variables in Mail Script

Shane J
Tera Guru

I'm trying to setup a mail script that will deliver the Variables from a RITM while maintaining carriage returns that occur in the text/string type variables.

Right now when I try to apply a ".replace" which works fine for other RITM fields, the Variables do not get returned at all (the entire script just seems to fail, and nothing is returned).

 

Here is the piece of the mail script giving me the trouble:

{
if (vs.get(i).toString().indexOf("Text") != -1){ //equals -1 if it never occurs in the String

//creates rows from Variables
template.print('<tr>');
template.print('<td align="right" valign="top" width=50%>' + vs.get(i).getLabel() + ': ' + '</td>' + '<td align="left" valign="top" width=50%>' + '&nbsp;&nbsp;' + vs.get(i) + '</td>');
}
else {
template.print('<tr>');
template.print('<td align="right" valign="top" width=50%>' + vs.get(i).getLabel() + ': ' + '</td>' + '<td align="left" valign="top" width=50%>' + '&nbsp;&nbsp;' + vs.get(i).getDisplayValue() + '</td>');

}

 

The part in bold is what I've been unable to get carriage returns to work for.  I have successfully used:

string_field.replace(/(\r\n|\n|\r)/g,'<br />');

(for example) to get the RITM Description to properly show carriage returns.

9 REPLIES 9

Omkar Mone
Mega Sage

Hi 

replace(/(\r\n|\n|\r)/gm,"").trim();

Try this once .

 

Tried:

 

template.print(vs.get(i).getDisplayValue().replace(/(\r\n|\n|\r)/gm,"").trim());

 

And did not work.

Hi 

template.print(vs.get(i).getDisplayValue().replace(/(\r\n|\n|\r)/gm,"with_what_you_want_to_relace?").trim());

Nope:

template.print(vs.get(i).getDisplayValue().replace(/(\r\n|\n|\r)/gm,"<br />").trim());

 

Looks like this if I don't try to get carriage returns: