First Name Personalization in email | Community
Skip to main content
New Participant
March 30, 2022
Solved

First Name Personalization in email

  • March 30, 2022
  • 1 reply
  • 4193 views

Hi all,

 

Hoping someone could help me with this. Been trying to send out an email with personalization on the first name based on subscribers job title. If theyre a listed as an MD we want the intro to Be Dr, (last name) otherwise just display their first name. My understanding is that this can be done using a velocity script and a simple IF statement but i have been unable to get this to display anything in my tests. 

Ive made sure the fields are checked off aswell. Here is what ive come up with. Ive inherited this task from a previous employee so anyhelp would be appreciated

#if(${lead.Title} == "MD")
#set($greeting = "Dr.$(lead.LastName},")
#else
#set($greeting = "${lead.FirstName},")
#end

 

 

In the actual email body ive tried referencing the token and the greeting field, both of them however display nothing.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Darshil_Shah1

You need to print the greeting variable after setting it in the if-else construct, can you try the script below?

 

#if($lead.Title.equals("MD")) #set($greeting = "Dr. $lead.LastName,") #else #set($greeting = "$lead.FirstName,") #end ${greeting}

 

If required, you can further use conditional statements to set the default values in the greeting variable for handling the empty  firstname/lastname field case.

Thank you!

1 reply

Darshil_Shah1
Darshil_Shah1Accepted solution
Community Manager
March 30, 2022

You need to print the greeting variable after setting it in the if-else construct, can you try the script below?

 

#if($lead.Title.equals("MD")) #set($greeting = "Dr. $lead.LastName,") #else #set($greeting = "$lead.FirstName,") #end ${greeting}

 

If required, you can further use conditional statements to set the default values in the greeting variable for handling the empty  firstname/lastname field case.

Thank you!

Jo_Pitts1
Community Manager
March 30, 2022

@nnuzzo ,

You'd made a good start!

 

Further to @darshil_shah1's post, there are a few other things to consider:

  1. Make sure lead.Title is selected in the object tree on the right hand side of the velocity editor.
  2. Darshil has moved your == to a .equals().  This is a more robust approach, and is how you should test for equality.
  3. You can separate @darshil_shah1's token in two if you want to display the greeting more than once.  This is what I tend to call 'set' and 'emit' tokens.  It would look something like this:
    {{my.setGreeting}}
    #if($lead.Title.equals("MD")) #set($greeting = "Dr. $lead.LastName,") #else #set($greeting = "$lead.FirstName,") #end​{{my.emitGreeting}}
    ${greeting}​

 

If you are ever likely to have more than one potential title/greeting combo (i.e. Sir, Professor, etc etc etc) then I'd go with a different approach to the initial determination based on a key map.  Let me know if you'd like to see that approach.

 

Cheers

Jo

nnuzzoAuthor
New Participant
March 31, 2022

Thanks both for the suggestions. I feel like im missing something incredibly basic because i still cant get these to work. 

Im using a list provided by the editor which is referencing a credential field instead of title so i made that revision to the code. I like the suggestion of having the 2 seperate tokens but when I implement it into the email its just display the following in tests:

 

March 24th, 2022

Dear ${greeting},

 

When calling out the token in the editor it should look like this correct? Sorry for the incredibly basic questions im sure this is something really simple that im just missing. 

 

March 24th, 2022

Dear {{my.emitGreeting:default=Valued Subscriber}},