SOLVED

First Name Personalization in email

Go to solution
nnuzzo
Level 1

First Name Personalization in email

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Darshil_Shah1
Level 10 - Community Advisor

Re: First Name Personalization in email

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!

View solution in original post

6 REPLIES 6
Darshil_Shah1
Level 10 - Community Advisor

Re: First Name Personalization in email

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
Level 10 - Community Advisor

Re: First Name Personalization in email

@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

nnuzzo
Level 1

Re: First Name Personalization in email

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}},

Darshil_Shah1
Level 10 - Community Advisor

Re: First Name Personalization in email

In case you're using separate tokens to set and emit the values - you need to include both the tokes in your email. The set token won't display anything but will make the data available for the emitgreeting token and evidently w/o including the set token, emit token would not have data to emit!

 

Also, velocity tokens are not designed to output the default values like the other tokens - you need to output the fallback/default value from the code itself.

 

Darshil_Shah1
Level 10 - Community Advisor

Re: First Name Personalization in email

Further to my earlier comment - you can refer below script to set the default values:

 

#if($lead.Title.equals("MD") && !$lead.LastName.isEmpty())
#set($greeting = "Dr. $lead.LastName,")
#elseif (!$lead.Title.equals("MD") && !$lead.FirstName.isEmpty())
#set($greeting = "$lead.FirstName,")
#else
#set($greeting = "Valued Subscriber")
#end
${greeting}

 

Logic in the if-else construct can be altered based on what and when you wanna show the default value. 

Jo_Pitts1
Level 10 - Community Advisor

Re: First Name Personalization in email

@nnuzzo ,

Can you paste in the token(s) you've created?

It won't render in the editor, but it should in the preview (as long as you are previewing by person)

Cheers

Jo