SOLVED

Custom Token With Email Scripting

Go to solution
Anonymous
Not applicable

Custom Token With Email Scripting

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: Custom Token With Email Scripting

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!

View solution in original post

14 REPLIES 14
Grégoire_Miche2
Level 10

Re: Custom Token With Email Scripting

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

Re: Custom Token With Email Scripting

and try

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

#if($thenickname.equals("))

or

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

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token With Email Scripting

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.

Anonymous
Not applicable

Re: Custom Token With Email Scripting

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

Re: Custom Token With Email Scripting

Hi Carley,

what "didn't work" mean?

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

-Greg

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom Token With Email Scripting

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!

Anonymous
Not applicable

Re: Custom Token With Email Scripting

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

Anonymous
Not applicable

Re: Custom Token With Email Scripting

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!

Liz_Davalos
Level 3

Re: Custom Token With Email Scripting

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}