Re: Creating a New Line Program Token to Organize a History Field

Nate_Oosterhous
Level 7
Hello Everyone!

I really need your help on this one.  

Question: Does anyone know how to create a program token that would create a new line if added to inbetween tokens.  

I am looking to format a history field like the example below:

Filled out Form on: 2015-03-10 13:00:00  Form Comments: This is the comments from the 3rd form fill out.

Filled out Form on: 2015-02-10 12:00:00  Form Comments: This is the comments from the 2nd form fill out.

Filled out Form on: 2015-01-10 11:00:00  Form Comments: This is the comments from the 1st form fill out.

Right now it looks all mashed together like this:

Filled out Form on: 2015-03-10 13:00:00  Form Comments: This is the comments from the 3rd form fill out.
Filled out Form on: 2015-02-10 12:00:00  Form Comments: This is the comments from the 2nd form fill out.Filled out Form on: 2015-01-10 11:00:00  Form Comments: This is the comments from the 1st form fill out.

Below is my Flow Action: 


0EM50000000SyWM.jpg

I am looking to figure out some way to use a program token in the default choice of this Change Data Value Flow.  Right now I have a program token in the place where I want it but I can't figure out how to get that to represent two new lines.

 
Tags (1)
47 REPLIES 47
Dan_Stevens_
Level 10 - Champion Alumni

That did not work:

Which is what's really bizarre since I tried three different types of line-breaks in my tests:

  1. Your technique (the focal point of this post)
  2. Using the ENTER key
  3. Using SHIFT-ENTER

Just for the heck of it, I tried ${lead.Lead_Notes.replaceAll("e","<BR>")} and got this:

pastedImage_0.png

So the issue is clearly with the hidden line-break character.

SanfordWhiteman
Level 10 - Community Moderator

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

Dan_Stevens_
Level 10 - Champion Alumni

Here's the output:

108
105
110
101
49
32
108
105
110
101
50
32
108
105
110
101
51

SanfordWhiteman
Level 10 - Community Moderator

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?

Dan_Stevens_
Level 10 - Champion Alumni

You mean here?  If so, then yes.  These were all entered as:

line1<ENTER>

line2<ENTER>

line3

pastedImage_0.png

SanfordWhiteman
Level 10 - Community Moderator

Maybe we should get on a call and figure this out. Send me an email...

Dan_Stevens_
Level 10 - Champion Alumni

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 ?

Dan_Stevens_
Level 10 - Champion Alumni

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")

SanfordWhiteman
Level 10 - Community Moderator

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.

Dan_Stevens_
Level 10 - Champion Alumni

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.

SanfordWhiteman
Level 10 - Community Moderator

Sure, that code above with replaceAll() changing every char (".") to "<br>".

Dan_Stevens_
Level 10 - Champion Alumni

Now we're unable to run any VS - look at the right panel:

pastedImage_0.png

SanfordWhiteman
Level 10 - Community Moderator

Mine looks okay, though.

Dan_Stevens_
Level 10 - Champion Alumni

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.

SanfordWhiteman
Level 10 - Community Moderator

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.

Alex_Shelukhano
Level 2

Hi guys,

I have the same problem with removed line breaks. Did you try to contact Marketo support to resolve the issue?

Thanks

Dan_Stevens_
Level 10 - Champion Alumni

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.

Matjaž_Jaušove2
Level 7

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.

SanfordWhiteman
Level 10 - Community Moderator

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.

lillyfalcon
Level 3

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

Screenshot 2023-08-21 at 3.35.45 pm.png

but not in email alerts 

Screenshot 2023-08-21 at 3.36.32 pm.png

 

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 

 

Screenshot 2023-08-21 at 3.38.43 pm.png

I've tried contacting Marketo support but they said they cant help with velocity script syntax.

 

Any help would be much appreciated! 🙂 

Lilly Falcon
SanfordWhiteman
Level 10 - Community Moderator

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>")}