[SalesForce] Flow not recognizing enter key/line breaks in long text area field

I hav a flow that fetches data from a custom long text area field and populates its values in the contentnote.

I have used HTMLEncode() in my flowformula so that it includes any spl characters in the long text area field.

My issue is the flow is not capturing 'Enter keys' or line breaks that i have added in the custom long text area field . it displays as a one complete line in the contentnote…PLzzz help

Just onemore qn..I need to display a particular Text Template content as coloured font or highlighted/underlined format in my contentnote record. The issue is i tried using tag and all that displays a flow exception when i try to save the record

enter image description here

Best Answer

I think if you put this in a formula in your flow it should work for you:

SUBSTITUTE( JSENCODE( {!fieldname} ) , '\r\n', '<br>')

The substitute function simply replaces the new line character '\r\n' with the tag you need <br>. The JSENCODE encodes your field as save for javascript. I don't think that should be necessary, but without it the formula won't recognize the line breaks. (I tried something like 12 different forms of line break, and got none of them to be recognized by the substitute function.

Edit: @horzel_evh provides some interesting insights in a separate answer. He/she points out that line breaks can be stored as \r\n or as \n. I thought Salesforce would store all the \n as \r\n but I just tried and it doesn't. The following formula would therfore be more robust:

SUBSTITUTE( SUBSTITUTE( JSENCODE( {!fieldname} ), '\r\n', '<br>'), '\n', '<br>')