Marketo’s velocity email scripting language allows you to create highly personalized emails, based on field values in your Marketo database. The scripting language can be used as a token within emails and as an alternative to Marketo’s dynamic content feature. Here are 4 examples of how you can use velocity scripts for more personalized Marketo emails.
Creating Velocity Scripts
Velocity scripts are created within a token under marketing activities inside a program or a folder.
Examples
Capitalize First Letter of the Lead’s First Name
This will captitalize the first letter of the lead’s first name, even if the value in the Marketo database is lowercase.
1 2 3 4 5 6 |
#set ($fname = ${lead.FirstName}) #if($fname.equals("")) there #else $display.capitalize($fname) #end |
Hide First Name Salutation if the First Name Field is Empty
Hide the first name salutation if the first name field is empty using this script.
1 2 3 4 5 |
#set ($fname = ${lead.FirstName}) #if($fname.equals("")) #else Hello ${lead.FirstName}), #end |
Greeting Based on Gender
Change the greeting in an email to Ms or Mr based on the lead’s gender.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
##check if the lead is male #if(${lead.MarketoSocialGender} == "Male") ##if the lead is male, use the salutation 'Mr.' #set($greeting = "Dear Mr. ${lead.LastName},") ##check is the lead is female #elseif(${lead.MarketoSocialGender} == "Female") ##if female, use the salutation 'Ms.' #set($greeting = "Dear Ms. ${lead.LastName},") #else ##otherwise, use the first name #set($greeting = "Dear ${lead.FirstName},") #end ##print the greeting and some content |
Display Different Text Based on a Field Value
Display different text in an email based on a field value. This can be a little bit easier than setting up dynamic content, since you don’t have to create segmentation rules.
1 2 3 4 5 6 7 |
#if(${lead.fieldname} == "fieldvalue1") Email text here #elseif (${lead.fieldname} == "fieldvalue2") Email text here #else Email text here #end |
Questions?
Email me, send me a tweet @jennamolby, or leave a comment
Thanks for this tip Jenna, you’ve saved me a lot of trouble again ;-)!
I’m a Salesforce developer and using velocity script for the first time! This post is really useful. I have a different use case though. I want to show specific field value from a Salesforce Custom object record (which is linked to Salesforce Contact/Marketo lead) in the email body. It works if the Lead has only one related custom object record (Onboard__cList has only one element) but doesn’t work if there are multiple.
#set($foo = $Onboard__cList.get(0).IC_Name__c)
$foo
I am a novice to all of the Velocity scripting but I used the hide the first name if empty script and had to modify it slightly to work.
I changed this:
#set ($fname = ${lead.FirstName})
#if($fname.equals(“”))
#else
Hello ${lead.FirstName}),
#end
to this:
#set ($fname = ${lead.FirstName})
#if($fname.equals(“”))
#else
Hello ${lead.FirstName},
#end
Had to lose the ) after the else’s lead.FirstName.
Also, how would I combine the hiding the first name and the capitalization of the first name? That would be handy, I would imagine.
Thank you for writing this!
Sorry, Blog formatted that a bit awkwardly.
Basically change Hello ${lead.FirstName}), to Hello ${lead.FirstName},
This is a really great post. Thanks a bunch for the pointers.
There’s a weird issue that I noticed occurring where if I use the “capitalize first name” script, it gives me an unwanted space after the lead’s first name. So it would look like this:
Hello Name ,
Have you noticed this before?
Hi Danny, Glad you like the post! Yes, I’ve seen that before. Is the comma in the email or in the script? I found that if you put the comma in the script there’s no space after it, for example: Hello $display.capitalize($fname), Let me know if that works for you.
Hey Jenna, I swear Marketo can be so strange sometimes. I tried your suggestion earlier and it removed the comma from the token and email. Although I might have forgotten to save it… Either way, it looks good now! Thanks so much!