RE: splitting text area string a newline in Advanced PDF Template

I have a custom body transaction field defined as a text area and am trying to add the text of this field into my Advanced PDF Template for my purchase orders.  I want to split the text into an array of the lines so that I can print each line in a table row so that longer messages will page-break nicely.  With the text value below as an example if I split this using a comma I end up with 3 “lines”:

If the field contains the following value:

“Hi Nick,

How are you today?



<#assign lines = record.custbody_text_message?split(",")>
<#list lines as line>

However; what I am trying to do is split the lines on the “newline” such that I should end up with total of 4 lines.  I cannot seem to find a way to get it to work.  I have tried all of these variations of arguments with the split function:

<#assign lines = record.custbody_text_message?split("\r\n", "r")>
<#assign lines = record.custbody_text_message?split("\r?\n", "r")>
<#assign lines = record.custbody_text_message?split("\r?\n+", "r")>
<#assign lines = record.custbody_text_message?split("(\r?\n)+", "r")>
<#assign lines = record.custbody_text_message?split("\\r\\n", "r")>
<#assign lines = record.custbody_text_message?split("\\r?\\n", "r")>
<#assign lines = record.custbody_text_message?split("\\r?\\n+", "r")>
<#assign lines = record.custbody_text_message?split("(\\r?\\n)+", "r")>

All of the above and many other deviations have failed to produce anything but the entire message as the first and only return value.  I’ve read extensively and and the links to oracle relating to splitting strings in java.  I can’t figure out what I’m doing wrong.  Any help is greatly appreciated!

wilsonsdev Rookie Asked on February 20, 2021 in How To's.
Add Comment
1 Answers


The only other thing I can think is to try some variations of

<br />, <br>, etc.



Advanced Answered on February 20, 2021.

Thanks Chris.  Yeah I tried those as well thinking maybe they string had already been interpolated by the time I was getting a handle on it in the PDF template but still no luck 🙁

on February 20, 2021.

Have you tried it without the second “r” argument?

on February 20, 2021.

You know I’ve tried so many things I just decided to go back and retry your suggestions again and the first thing I tried worked!  I think prior attempts I was erroneously trying to replace the br tag using regex still.

<#assign lines = record.custbody_text_message?split("<br />")>

Thanks for the help Chris…a good majority of a day of frustration is now behind me!

on February 20, 2021.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.