SOLVED

Modifying field values using velocity script?

Go to solution
Guitarrista82
Level 6

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

1 ACCEPTED SOLUTION
SanfordWhiteman
Level 10 - Community Moderator

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.

View solution in original post

28 REPLIES 28