Re: Email Script Token, First Name Field

Stephanie_O_Rei
Level 2

Email Script Token, First Name Field

Hi there,

 

We have leads that have a first name of [Not Provided], and we'd like to say if we identify the first name as such, fill in "there" as the value, if not identified as [Not Provided] use the value that lives in the field. 

We have used as the token name: 

{{my.First Name Script}}

{{lead.First Name:default=there}}

I have used the following tokens and I am still running into the issue;

 

#if ($lead.FirstName == "[Not Provided]")

 

there

 

#elseif ($lead.FirstName == "")

 

there

 

#else

 

$lead.FirstName

 

#end

**************************************************************************************************************

#if( $lead.FirstName.equals("[Not Defined]") || $lead.FirstName.isEmpty() )  

there  

#else  

$lead.FirstName  

#end  

***************************************************************************************************************

 #if( $lead.FirstName.equals("[Not Provided]") || $lead.FirstName.isEmpty() )there#else $lead.FirstName#end

**************************************************************************************************************

#if(${lead.First Name} == “[Not Provided]” || ${lead.FIrst Name} == “”)
 $set($greeting = “Hi there,”)
#else
 $set($greeting = “Hi ${lead.First Name},”)
#end${greeting}

Any insight on this would be greatly appreciated. I have tried all the above values and we are still getting a Hi [Not Provided]. 

Thank you! 

4 REPLIES 4
Chris_Wilcox
Level 9

Re: Email Script Token, First Name Field

Few things to confirm:

  1. Make sure the "First Name" field is checked in the integration pane on the right side of the token editor window. 
  2. If it is, try unchecking, saving your token, opening it back up and -- here's the critical part -- waiting until that integration fully loads before touching the popup window, THEN rechecking the box, saving and testing. In my experience, if you start to interact with anything in that popup before the integration pane loads (2-3 seconds), it can break something on the back. Unchecking and rechecking all of the integrations used in that token seems to fix it. It's dumb, but something to try. 

I just created a test record and used the code below which worked as expected to hide "[Not Provided]" from the greeting. Note, I prefer to use exclusionary logic vs. inclusionary logic for things like this (i.e. they have to qualify your rules to get the custom name, instead of the custom name being the default value). 

Sanford is probably going to hate this code because it doesn't use the javascript markup, but in my personal opinion the simple markup works just fine for something like this.  

##Confirm First Name is not provided or is blank
#if ($lead.FirstName != '[Not Provided]' && $lead.FirstName != "")
Hi $lead.FirstName,
#else
Hi there,
#end‍‍‍‍‍‍‍‍‍‍‍‍
SanfordWhiteman
Level 10 - Community Moderator

Re: Email Script Token, First Name Field

Do you mean formal vs. simple references, Chris? I never use the term "JavaScript markup" (would be very confusing as Velocity has nothing to do with JS!).

Anyway, I don't hate it! ...

... but I don't like leaning on the type-juggling == and != operator. They'll appear to work, until they don't because of mismatched object types. In contrast, equals() and isEmpty() always work the same in any context, because they are typed. It's better to rely on those methods from the start, instead of getting bitten badly by an error and then switching to them.

It's also less confusing if null values don't match the first condition; even if you don't expect any nulls on the Lead object (only Strings) they're always possible on Custom Objects.

##Use First Name if not null, not blank, and not special placeholder string
#if( $lead.FirstName && !$lead.FirstName.isEmpty() && !$lead.FirstName.equals("[Not Provided]") )
Hi ${lead.FirstName},
#else
Hi there,
#end‍‍‍‍‍‍
Chris_Wilcox
Level 9

Re: Email Script Token, First Name Field

Hah! I don't even know the lingo, yes formal vs. simple  

Stephanie_O_Rei
Level 2

Re: Email Script Token, First Name Field

This worked and was so helpful. Thank you!!