Re: Conditional First Name Token

Anonymous
Not applicable
Hi,

We have several leads in our SFDC with first name as [First Name] as a placeholder.  When using the first name token in the email, I don't want [First Name] to be visible. Instead, I want the default value to be visible.

Does anyone know how to do this?

Thanks in advance!

-Kelly


Tags (1)
16 REPLIES 16
Scott_McKeighe2
Level 5

The solution we use to get around this problem is a simple velocity email script token.

Essentially, this token looks at the value of the lead's first name, and if it's a default/blank value, we change the greeting to something generic, otherwise greet them by name.

Looks kind of like this:

#if (${lead.FirstName} == "")

Greetings from MyCompany!

#else

Hi ${lead.FirstName},

#end

Inside the email, you simply put the my.token for your email script in place of whatever salutation you had prior.

Another option, if you're not averse to adding fields to your instance, is to go with a Formula Field that evaluates the lead's first name.

Hope this helps!

Anonymous
Not applicable

This is great, Scott but I'm still having some trouble. If the first name field is empty, I don't want to have any greeting there at all. Any thoughts? Thanks in advance!

Scott_McKeighe2
Level 5

Hey Robin!

I would utilize Sanford Whiteman​ 's solution here. It's the most elegant and simple form of this IF/THEN velocity for salutation.

In our use case, we needed to be able to pivot the salutation based on the recipient's honorifics. So a Doctor would get "Hi Dr. Smith," whereas a staff member would get "Hi James,".  To that end, you could really customize a salutation to whatever fits your business need, since you're evaluating a field's value to produce a desired output.

SanfordWhiteman
Level 10 - Community Moderator

#if( !$lead.FirstName.isEmpty() )

Hello ${lead.FirstName}.

#end

(But really you should open a new thread instead of resuscitating an old one, since otherwise it'll never have a Correct answer.)

Anonymous
Not applicable

Thanks so much, Sanford. Am I doing something wrong? I'm getting this where is no first name. Happy Holidays, BTW!

pastedImage_0.png

SanfordWhiteman
Level 10 - Community Moderator

Make sure First Name is selected in the treeview on the right side of the script editor.

Anonymous
Not applicable

You're a lifesaver!! Thanks so much!

SanfordWhiteman
Level 10 - Community Moderator

Great! Mark as Correct​ when you get a chance?

Dory_Viscoglio
Level 10

Not a new thread so they can't mark as correct   New threads are important.

SanfordWhiteman
Level 10 - Community Moderator

Ah yes. I wouldn't bother opening this idea, but it would be cool if you could "fork" a thread to take ownership.

Grégoire_Miche2
Level 10

And opening new threads also guarantees that many more people will see it, notice it and will be likely to provide an answer.

-Greg

Grégoire_Miche2
Level 10

HI Robin,

With the Velocity scripting language, you can create the whole block of words and create a sophisticated logic with multiple if's or cases.

-Greg

Anonymous
Not applicable

Hi Kelly,

Sorry this is so late to the game, but you could ultimately use an email script to choose which field to send. In the velocity script, you could have a formula similar to what you are imagining that would use the first name only if it did not equal a certain value. If it did, then you can use another field.

Best,
Erik

Anonymous
Not applicable
Hi Kelly,

To pick up where Dory left off here, the short answer to your question is essentially "yes".  You would want to clone the version of your email using the first name token, then in the second version, simply remove the token.

The way tokens work is that they will either display the value in the Salesforce field that it is calling, or if the field is empty it will display the fallback/default value.

I would suggest you look into Dory's suggestion of using segmentation as well.  If [First Name] is widespread in your database, setting up a segment to separate out that value could save you lots of time from cloning emails in the long run.
Anonymous
Not applicable
Thanks Dory for your quick reply!

I was hoping to use something like an IF statement/formula. It sounds like tokens doesn't have that functionality other than "default?" Is that correct?

If we used the alternative email, would we have to clone the original email and then just remove the token in that version?

I don't know much about dynamic content and segments. We are also trying to find a solution that isn't too complicated.

Thanks again for your help!
Dory_Viscoglio
Level 10
Hi Kelly, I think the easiest way is to have a separate version of the email, and in the flow steps of the campaign if first name is [First Name], then you send them the alternate version of the email. Another method would be using dynamic content and segments, but that is probably more trouble than it's worth if you don't already have these people segmented out.