Hi Marketo Community,
I am looking to build a custom token to do the following:
I want to use the Nickname field if it is not empty, but if Nickname is empty I want to use the First Name field.
I believe this can be achieved by using the velocity email scripting tool, and have come up with the following, which appears correct to me but is only populating First Name (and yes, I tested it on leads with the Nickname field as not empty).
#if ("${lead.Nickname_c}" != "" )
#set ($greeting = "Dear ${lead.FirstName},")
#else
#set ($greeting = "Dear ${lead.Nickname_c},")
#end
${greeting}
I have also tried using lead.Nickname_c.isEmpty and lead.Nickname_c.size = 0 as other options to check for empty field values. I did try null, even though it is technically not a null value if it is empty, which also did not work.
I am not a developer by any stretch of the imagination so it is quite possible I am missing something or am completely off base.
Thank you!
Solved! Go to Solution.
Hi Sanford,
Sorry for a duplicate reply, I just fixed this. The final version was:
#if (!$lead.Nickname__c.isEmpty())
#set ($greeting = "Dear ${lead.Nickname__c},")
#else
#set ($greeting = "Dear ${lead.FirstName},")
#end
${greeting}
Thank you again for all of your help!
Hi Carley,
Move your question to the "products" section. The champions group is for questions about the champions program. Many more people will see your question in the "products" section and will be likely to answer.
-Greg
and try
#set ($thenickname = ${lead.nickname__c})
#if($thenickname.equals("))
or
#if (!$lead.nickname__c.isEmpty())
-Greg
This is answered in a few other threads, to be sure...
First, you don't need the formal notation {} in an #if.
Second, Marketo will export an empty field as an empty string. So
$lead.Nickname__c.isEmpty()
is what you want (note the parens).
Make sure that both Nickname and FirstName are selected in the right-hand-side tree in Script Token Editor.
So I tried this and it didn't work:
#if (!$lead.nickname__c.isEmpty())
#set ($greeting = "Dear ${lead.FirstName},")
#else
#set ($greeting = "Dear ${lead.Nickname_c},")
#end
${greeting}
I also made sure that both fields were selected.
Hi Carley,
what "didn't work" mean?
Are you sure you have a value in either nickname OR firstname ?
-Greg
Your script has...
Velocity is case-sensitive (and of course spelling-sensitive). Fix up the logic and it'll work!
Hi Sanford, thank you so much for your help. I have made the adjustments I think you were writing about and came up with the below:
#if (!$lead.Nickname__c.isEmpty())
#set ($greeting = "Dear ${lead.Nickname_c},")
#else
#set ($greeting = "Dear ${lead.FirstName},")
#end
${greeting}
When I sent a test doing this to a lead WITH a Nickname and First Name I received:
Dear ${lead.Nickname_c},
It seems I am getting closer, but still missing something. Could you send me what you think this should look like please?
Thank you for your time.
Carley Donovan
Hi Sanford,
Sorry for a duplicate reply, I just fixed this. The final version was:
#if (!$lead.Nickname__c.isEmpty())
#set ($greeting = "Dear ${lead.Nickname__c},")
#else
#set ($greeting = "Dear ${lead.FirstName},")
#end
${greeting}
Thank you again for all of your help!
Hey, I just edited this for my own use and can't get it to work (It sends the sample email, but seems to only print the space in the else statement), here's what I have (I'm still learning this script so obvious errors are likely):
#if (!$lead.FirstName.isEmpty())
#set ($greeting = "")
#else
#set ($greeting = " ${lead.FirstName}")
#end
${greeting}