Hello Community!
I am reviewing how to use Velocity Script for modifying tokens, content in emails, etc. I came across a script that looks like it might be useful in solving a current problem.
We are using a token {{Lead.Sub Partner}} to identify various Sub Partner classes, i.e. Presidential, Chairman's Club, Select, etc.
The problem is that when some of our contacts were imported into Marketo from an excel document, the apostrophe got transposed into some unnecessary characters: Marriott - Chairman’s Club.
Would it be possible to use the script below to change this Sub Partner name to this? Marriott - Chairman's Club?
#set( $lead.SubPartner )
#if( $lead.SubPartner contains("Marriott - Chairman’s Club") )
Marriott - Chairman's Club
#end
Or am I way off here?
Thank you much,
LK
Solved! Go to Solution.
I am reviewing how to use Velocity Script for modifying tokens, content in emails, etc. I came across a script that looks like it might be useful in solving a current problem.
First — I wouldn’t use the expression “modifying tokens”. A Velocity token is a {{my.token}}. You probably mean “modifying field values” (I changed your post title for clarity).
Velocity can certainly modify how fields appear in email content. That’s one of the things it’s for: formatting and localizing dates and currencies, changing string capitalization, summing numbers, etc.
However, this particular situation you’re talking about isn’t one of “unnecessary” characters.
It’s that someone chose the wrong text encoding type when creating an import, so instead of the single UTF-8 character apostrophe (same as right single curly quote ’, not the same as straight single quote ') it was seen as 3 separate characters in Windows-1252.
This specific character sequence ’ could be replaced by ’ using .replace() since it’s unlikely those 3 chars were intended to be printed as-is, right next to each other.
But this isn’t going to fix all other encoding problems, ultimately you need to fix them at the source. Once something has been read in the wrong encoding, you can’t get the original encoding back out.
Thank you Sanford!
I updated the code as shown below, but am seeing an error when trying to preview it in email.
#set( $valueWithoutMarriottPrefix = $lead.subPartner.replaceAll("^Marriott - ","").replaceAll("^","a ").replaceAll("(?i)^a ([aeiou])","an $1") )
${valueWithoutMarriottPrefix}
What am I doing wrong?
Thank you,
LK
@SanfordWhiteman and @Guitarrista82 ,
Ignoring for a moment the value in a robust discussion on the use of Velocity, I have silly thought. Namely, why not fix this problem in the actual Marketo data?
Surely a smart campaign that had as its smart list the field with the junk value, and then a flow step doing a change data value to the correct value would suffice?
Cheers
Jo
@SanfordWhiteman I tried private messaging you but am not sure if the message went through because there was no confirmation on my end. Can you please confirm if the message was received?
Thank you,
LK
Thanks...I just resent and it looks like it was sent successfully this time.
Quite. The use case here seemed very specific, hence why I suggested it 🙂
Thank you for offering your insight, @Jo_Pitts1. Definitely not a silly thought.
I was able to fix the initial issue with the data by running a smart campaign in Marketo, but I received a request to transform how the existing values for the custom field appear in emails.
Unfortunately, our CRM is rather archaic and the management of data therein is not an easy undertaking. A request to change data values would most likely take several months to complete. And any data that flows in from our CRM to Marketo would override any values that get updated.
Definitely food for thought for longer-term implementation, but at the moment, it wouldn't be feasible with our time constraints.
Thank you,
LK