Custom Token With Email Scripting | Community
Skip to main content
March 2, 2017
Solved

Custom Token With Email Scripting

  • March 2, 2017
  • 2 replies
  • 5135 views

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!

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by

Your script has...

  • different capitalization for nickname__c and Nickname_c
  • different spelling for nickname__c and Nickname_c
  • the logic backwards for checking if they have a Nickname
    • if( !$<your condition> ) means if the condition is not true (literally, if not the condition is true)
    • if( !$lead.nickname__c.isEmpty() ) means "If they have a nickname filled in..." ("If not nickname is empty")

Velocity is case-sensitive (and of course spelling-sensitive). Fix up the logic and it'll work!


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!

2 replies

Grégoire_Miche2
Level 10
March 2, 2017

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

Grégoire_Miche2
Level 10
March 2, 2017

and try

#set ($thenickname = ${lead.nickname__c})

#if($thenickname.equals("))

or

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

-Greg

SanfordWhiteman
Level 10
March 2, 2017

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.

March 2, 2017

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.

Grégoire_Miche2
Level 10
March 2, 2017

Hi Carley,

what "didn't work" mean?

Are you sure you have a value in either nickname OR firstname ?

-Greg