9 Replies Latest reply on Mar 7, 2017 1:00 PM by Gerard Donnelly

    Velocity token - salutation emails

    Tom Liolios

      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

        • Re: Velocity token - salutation emails
          Sanford Whiteman

          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]}
          
          3 of 3 people found this helpful
            • Re: Velocity token - salutation emails
              Tom Liolios

              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:

              • lead.new_gender  (which is always male, female or empty)
              • lead.Full_Name (which should be part of the output --> "Sehr geehrte Frau [Full Name] or Sehr geehrter Herr [Full Name]
              • and of course I have the {{my.token}}, which I named my.GermanSalutation

               

              Would you be able to help me out with a code that works with these fields?

               

              Appreciate it!

               

              Thanks,

              Tom

                • Re: Velocity token - salutation emails
                  Sanford Whiteman

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

                  1 of 1 people found this helpful