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.
Solved! Go to Solution.
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!
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!
@nnuzzo ,
You'd made a good start!
Further to @Darshil_Shah1's post, there are a few other things to consider:
#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
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 |
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}},
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.
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.
@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