Email script - ${lead.Interest} contains "A" | Community
Skip to main content
Charles_THIERY
Level 2
December 9, 2016
Solved

Email script - ${lead.Interest} contains "A"

  • December 9, 2016
  • 1 reply
  • 7046 views

Hello,

I don't manage to find on the documentation a way to use VTL in order to make a #if conditions for searching a specific value coming from a Marketo field.

Does anybody could help me on this please?

eg:

<ul>

#if(${lead.Interest}.contains("Performance"))

    <li>Performance</li>

#end

</ul>

BR,

Charles

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 SanfordWhiteman

Still not working...

An error occurred when procesing the email Body!

Encountered "{" near

<ul>
#if(${{lead.Interest__c}}.indexOf('Performance'))
    <li>Performance</li>
#end

Should post to Products, not Champions (this space is to discuss the Champions program itself).

For a case-sensitive partial match you want

#if( $lead.Interest__c.contains("Performance") )

Note this will also match on "Power, LowPerformancer, Strength".

Matching that is less prone to error uses a regex:

#set( $item = "Performance" )

#if( $lead.Interest__c.matches("(?i)(.*)(^|,)\s*${item}\s*(,|$)(.*)") )

In general, "list-like" strings should be avoided unless you can make absolutely sure that the delimiter ("," in this case) cannot appear unescaped within an item. That is, if an item has a comma inside it -- which is totally possible with a string unless you control all the input -- parsing becomes problematic. Instead use a known structure like a JSON array.

(Geoff, you don't need curlies around a token if it isn't enclosed within quotes or output.)

ETA: Putting the matching item in a separate var will be more maintainable.

1 reply

gkrajeski
Level 10
December 9, 2016

You should likely be able to use ${{my.token}}.indexOf('A')

eg:

<ul>

#if(${lead.Interest}.indexOf("Performance"))

    <li>Performance</li>

#end

</ul>

Charles_THIERY
Level 2
December 9, 2016

Hi Geoff,

Thanks for the quick reply but I got this error:

An error occurred when procesing the email Body!

Lexical error, Encountered: "i" (105), after : "." at *unset*[line 90, column 25] near

<ul>
#if(${lead.Interest}.indexOf("Performance"))
    <li>Performance</li>
#end
</ul>

Maybe, I should clarify what I'm looking for:

My field ${lead.Interest} contains value like "A, B, C, D, ..." and I want to test on a specific value for creating a bullet point.

Any guess on why it's not working please?

gkrajeski
Level 10
December 9, 2016

woops.... need double curly braces around the token... my bad