That did not work:
Which is what's really bizarre since I tried three different types of line-breaks in my tests:
Just for the heck of it, I tried ${lead.Lead_Notes.replaceAll("e","<BR>")} and got this:
So the issue is clearly with the hidden line-break character.
Yeah, the question is what on Earth could that character be in your instance?
The {{token}} expressly contains a single \n.
We've now tried Velocity replacement expressions on \r\n, \n, and just \r!
Try this and post the output:
#foreach( $char in $lead.Lead_Notes.toCharArray() )
$lead.Lead_Notes.codePointAt($math.sub($velocityCount,1))<br>
#end
Here's the output:
108
105
110
101
49
32
108
105
110
101
50
32
108
105
110
101
51
That shows that the newlines are spaces (char 32) in your Velocity context! What the?!?
And yet the newlines are preserved in the UI when you refresh the page?
You mean here? If so, then yes. These were all entered as:
line1<ENTER>
line2<ENTER>
line3
Maybe we should get on a call and figure this out. Send me an email...
Sandy, thanks for taken the call with me yesterday. I went ahead and cloned the working alert email that gets sent as part of a trigger campaign. That email failed to render as well. The commonality in all of this testing is that it seems to work with trigger campaigns, but not batch campaigns (all my tests were done using batch campaigns). Are you aware of any limitations in using specific velocity methods with batch campaigns (similar to how you cannot use tokens in the "send alert" flow step as I mentioned here: Sales Alert Batch Campaign ?
So I went ahead and created a test trigger campaign and all tests rendered successful. So I've confirmed (unless proven otherwise) that when velocity scripts - or maybe just some - are used within alert emails that are part of a batch campaign, only the token itself will render, and not transformations on that token. For example, this:
${display.br($lead.avanadeInterestingMomentHistory)}
will not insert <br> for all line-breaks, but it will display the unaltered value contained in the lead field (in this case "Avanade Interesting Moment History")
I don't think that's it: I think it's that the linebreaks are changed to spaces, so .br() runs but has nothing to do.
Is there another type of "search/replace" script that can be used on normal text strings? I can then run it on something we can see; and something that's present in both batch and trigger campaigns.
Sure, that code above with replaceAll() changing every char (".") to "<br>".
Now we're unable to run any VS - look at the right panel:
Mine looks okay, though.
Mine's ok now as well. Not sure what that was all about. Anyway, I just ran that script using a batch and trigger campaign - and it rendered fine both times:
"test1 test2 test3" transformed to "DAN1 DAN2 DAN3"
So your theory is back on the table.
So I think the way to address it is Why is Marketo changing linebreaks to spaces only for batches? I wonder if anyone else is lurking on this thread and can share their findings.
Hi guys,
I have the same problem with removed line breaks. Did you try to contact Marketo support to resolve the issue?
Thanks
Alex - we created a support ticket back on Aug. 1. Marketo was able to reproduce this behavior (where it only rendered properly with trigger campaigns but not batch campaigns. But since this is a P3 ticket, Support does not have the capacity to look further into this at this time. Yes, frustrating.
Hi all,
this is probable a bit outdated, however, we run into the same problem and what did the trick for us was just removing the curly brackets from the script:
${display.br($lead.fieldName)} --> $display.br($lead.fieldName)
I am not a programmer, so I can't explain why it worked, but maybe it will help somebody.
Mmm, neither of these can have any effect when line breaks do not exist at all in the source string.
They're also completely identical once parsed by the Velocity engine.
hey @SanfordWhiteman @DanB did you manage to find a solution for the line break not displaying in email alerts?
I inherited these scripts:
${lead.legalvisionEmailClickHistory.replaceAll("%newline%","<br/>")}
${lead.legalvisionInterestingMomentsHistory.replaceAll("%newline%","<br/>")}
${lead.legalvisionWebPageHistory.replaceAll("%newline%","<br/>")}
but they were not working so I created {{my.line-break}} using method described in https://blog.teknkl.com/dark-mkto-alleys-line-break-token/# and replaced %newline% in flow step for {{my.line-break}}
however still no luck - this fixed the way the fields display in Marketo lead record
but not in email alerts
I also tried changing the scripts to the ones you mentioned but no luck:
${display.br($lead.legalvisionWebPageHistory)}
${display.br($lead.legalvisionEmailClickHistory)}
${display.br($lead.legalvisionWebPageHistory)}
These are my flow steps:
if custom field is empty
{{system.dateTime}}: {{trigger.Trigger Name}} {{trigger.Name}} {{trigger.Web Page}}
else
{{system.dateTime}}: {{trigger.Trigger Name}} {{trigger.Name}} {{trigger.Web Page}} {{my.line-break}}{{lead.legalvisionWebPageHistory}}
I'm using an html email template coded for Marketo and referencing the token as follows
I've tried contacting Marketo support but they said they cant help with velocity script syntax.
Any help would be much appreciated! 🙂
This is a longstanding Marketo bug.
A Textarea field’s line breaks (that is, \n = standard U+000A) are simply stripped out before the field is output. This unfortunately includes when you try to manipulate the value in Velocity: the line breaks are gone before Velocity could even get a change to turn them into HTML breaks (<br>).
The workaround — and it’s quite cumbersome — is to add another type of break in addition to the \n.
I like to use U+001E before the U+000A.
So in the Line Break Token setup, instead of
%5Cn
do
%5Cu001E%5Cn
Then in VTL you can split on that:
${display.list($lead.field.split("\u001e"),"<br>")}