Email Conditionals | Community
Skip to main content
Mal_Warwick
Level 2
November 28, 2018
Question

Email Conditionals

  • November 28, 2018
  • 1 reply
  • 4796 views

Hello,

I'm running into a bit of an issue when trying to apply conditionals. when it reaches the else condition, the lead.First Name is left blank when testing the email.

  #if ({{lead.First Name:default=Friend}})

  Testt

  #else

  {{lead.First Name}},  Testt

  #end

if some one has some pointers, greatly appreciated.

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

1 reply

SanfordWhiteman
Level 10
November 28, 2018

You seem to be mixing together different syntax.

In Velocity, variables (references) are denoted with a $dollarSign or only if proven necessary a ${formalReference} style with a dollar sign + single curly braces.

Your script should look like this:

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

Hi, Friendo!

#else

Hi, ${lead.FirstName}!

#end

Note how I used the formal reference style only in the line that creates output. You shouldn't use it anywhere else.

Mal_Warwick
Level 2
November 29, 2018

Hi Sanford,

Thank you for the reply, would I need to set this script into My Tokens? I'm pretty new to Marketo and have tried my best to look over documentation and follow the tutorials. apprecieate the help.

SanfordWhiteman
Level 10
November 29, 2018

Yes, you'd create an "Email Script" type of {{my.token}} (which is written in Velocity Template Language and also called a "Velocity token").

In the tree of fields on the right-hand side of the Script Editor window, make sure you've checked off FirstName, and any other fields you wish to process in Velocity. If you don't check them off, they aren't present and will always be seen as null.

Then you include the {{my.token}} in your email as with other tokens.

I can't recommend strongly enough that you read my posts on Velocity, both those on the official Products blog and additional posts (not cross-posted here to not overwhelm/overbore people) at blog.teknkl.com/tag/velocity.

Finally, when posting code to Community threads, always highlight it using the Advanced Editor's syntax highlighter:

https://s3.amazonaws.com/blog-images-teknkl-com/syntax_highlighter.gif

There's no highlighter specific to Velocity, but you can choose Java (not JavaScript) which is intimately related.