Hi all,
I would like to get some help with setting up a velocity script for a program token that should display the correct salutation in my German emails
--> In German, you need to differentiate between male and females in the salutation, and this also has an effect on how you write certain words.
I have absolutely no experience with creating such scripts, so it would be great if someone could easily explain what kind of script I should use.
I found the following script on http://developers.marketo.com/email-scripting/ . I copied it, and edited the tokens for the ones I use in my instance.
I made sure that the checkboxes for the necessary tokens are checked in the token editor.
Could someone look at this script, and provide any adjustments, as this is not working now.
##check if the lead is male
#if(${lead.new_gender} == "Male")
##if the lead is male
#set(${my.GermanSalutation} = "Sehr geehrter Herr ${lead.Full_Name},")
##check is the lead is female
#elseif(${lead.new_gender} == "Female")
##if female
#set(${my.GermanSalutation} = "Sehr geehrte Frau ${lead.Full_Name},")
#else
##otherwise, use the first name
#set(${my.GermanSalutation} = "Sehr geehrte/r Frau/Herr ${lead.Full_Name},")
#end
Appreciate all the help!
Thanks,
Tom
Solved! Go to Solution.
Thanks Dory... Tom there's nothing inherently wrong about the way you're generating the salutations, but I think you're misunderstanding how Velocity output works (but you should always detail what error/behavior you're seeing -- "not working" is usually a recipe for a response like "what do you mean by 'not working'").
For output, you don't want to #set anything, but the opposite: lines that don't begin with # become the value of the {{my.token}}. So if you have one line of output like
Sehr geehrter...
Then "Sehr geehrter" is the value of the {{my.token}} when inserted.
I would also advise using a more maintainable code structure when doing translation/dictionary/localization patterns like this. Separate your dictionary from the output itself. Allow for a range of languages later. And also don't use curly braces on #set lines where they aren't necessary and make the code more fragile.
#set( $currentLang = "de" )
#set( $salutations = {
"de" : {
"male" : "Sehr geehrter Herr ${lead.Full_Name}",
"female" : "Sehr geehrte Frau ${lead.Full_Name}",
"" : "Sehr geehrte/r Frau/Herr ${lead.Full_Name}"
}
} )
#if( $salutations[$currentLang].containsKey($lead.new_gender) )
${salutations[$currentLang][$lead.new_gender]}
#else
${salutations[$currentLang][""]}
#end
Note if the field New Gender in Marketo is only ever "male," "female," or empty, you don't need the extra failsafe condition at the end and can just use
#set( $currentLang = "de" )
#set( $salutations = {
"de" : {
"male" : "Sehr geehrter Herr ${lead.Full_Name}",
"female" : "Sehr geehrte Frau ${lead.Full_Name}",
"" : "Sehr geehrte/r Frau/Herr ${lead.Full_Name}"
}
} )
${salutations[$currentLang][$lead.new_gender]}
Thanks Dory... Tom there's nothing inherently wrong about the way you're generating the salutations, but I think you're misunderstanding how Velocity output works (but you should always detail what error/behavior you're seeing -- "not working" is usually a recipe for a response like "what do you mean by 'not working'").
For output, you don't want to #set anything, but the opposite: lines that don't begin with # become the value of the {{my.token}}. So if you have one line of output like
Sehr geehrter...
Then "Sehr geehrter" is the value of the {{my.token}} when inserted.
I would also advise using a more maintainable code structure when doing translation/dictionary/localization patterns like this. Separate your dictionary from the output itself. Allow for a range of languages later. And also don't use curly braces on #set lines where they aren't necessary and make the code more fragile.
#set( $currentLang = "de" )
#set( $salutations = {
"de" : {
"male" : "Sehr geehrter Herr ${lead.Full_Name}",
"female" : "Sehr geehrte Frau ${lead.Full_Name}",
"" : "Sehr geehrte/r Frau/Herr ${lead.Full_Name}"
}
} )
#if( $salutations[$currentLang].containsKey($lead.new_gender) )
${salutations[$currentLang][$lead.new_gender]}
#else
${salutations[$currentLang][""]}
#end
Note if the field New Gender in Marketo is only ever "male," "female," or empty, you don't need the extra failsafe condition at the end and can just use
#set( $currentLang = "de" )
#set( $salutations = {
"de" : {
"male" : "Sehr geehrter Herr ${lead.Full_Name}",
"female" : "Sehr geehrte Frau ${lead.Full_Name}",
"" : "Sehr geehrte/r Frau/Herr ${lead.Full_Name}"
}
} )
${salutations[$currentLang][$lead.new_gender]}
Hi Sanford Whiteman,
Thanks a lot for your help. I agree, saying that it is 'not working' is not that clear.
To be exact, I inserted the {{my.token}} in an email and sent it to a lead with the new_gender field set to male. The email came back blank.
I get what you're saying with allowing for more languages later. However, we're about to launch a campaign in Germany, so I need to get this working quite quickly. I only have these fields to my availability:
Would you be able to help me out with a code that works with these fields?
Appreciate it!
Thanks,
Tom
You don't have to refactor your code that much for it to work, but what you're missing is you don't #set the my.token *in the script*. All your output lines (any line that *doesn't* start with #) concatenated together automatically become the token value.
See the last line of my second snippet? That's an output line. It wouldn't matter what I had called the my.token: that token name is used *outside* the VTL code itself. Whatever I output from the code becomes the token value. If the script token is first called {{my.saluto}} and I change it to {{my.schmaluto}}, the value remains the same, without making any change to the code inside the script token at all. (You would of course change the token name in the email to pick up the new content.)
Hi Sanford,
It worked! My email with the salutation token now comes back with "Sehr geehrter Herr Tom Liolios"
I do not yet use the #set( $currentLang = "de" ) part in my instance, but it doesn't hurt if I leave it in the script for now right?
Thanks so much!
Great! And yes, you can leave that line in there -- no harm. I have a blog post on translations in Velocity coming out soon that I'll link to here. Meantime, if you could please mark my answer w/the code Correct.
I am completely new to Velocity Scripting and have been tasked with setting up German Salutation to auto populate. Can you tell me if this would work or what is wrong with it. Thanks in advance for any help.
#if (${lead.Salutation} == "")
Sehr geehrte/r Frau/Herr ${lead.last_Name}
#elseif
(${lead.Salutation} == "Herr")
Sehr geehrter Herr ${lead.last_Name}
#elseif
(${lead.Salutation} == "Frau")
Sehr geehrte Frau ${lead.last_Name}
#elseif
(${lead.Salutation} == "Herr Dr.")
Sehr geehrter Herr Dr. ${lead.last_Name}
#elseif
(${lead.Salutation} == "Frau Dr.")
Sehr geehrte Frau Dr. ${lead.last_Name}
#elseif
(${lead.Salutation} == "Herr Prof.")
Sehr geehrter Herr Prof. ${lead.last_Name}
#elseif
(${lead.Salutation} == "Frau Prof.")
Sehr geehrte Frau Prof. ${lead.last_Name}
#elseif
(${lead.Salutation} == "Herr Prof. Dr.")
Sehr geehrter Herr Prof. Dr. ${lead.last_Name}
#elseif
(${lead.Salutation} == "Frau Prof. Dr.")
Sehr geehrte Frau Prof. Dr. ${lead.last_Name}
#end
If you open another thread I'm happy to answer.
Hi,
Thanks a lot. I just opened a new thread and tagged you in it.
German Salutation - Velocity Script
Kind regards,
Gerard