SOLVED

Velocity script isn't working

Go to solution
samsoto
Level 2

Velocity script isn't working

I am trying to create a token that generates values based off a field called Preferred Location. Below is the velocity I am using. 

#if(${lead.preferredLocation} = "Brea")
<p style="padding: 0; margin: 0;text-align: center;font-weight: bold;">BREA</p>
<span class="Georgia, Times, "Times New Roman", serif;"></span>
<p style="padding: 0; margin: 0;text-align: center;">375 W. Birch Street Suite 1-A</p>
<span class="Georgia, Times, "Times New Roman", serif;"></span>
<p style="padding: 0; margin: 0;text-align: center;">Brea, CA 92821</p>
#end

 

I dropped the token in the email and when I go to preview the email I receive this message. What is wrong here?

Screen Shot 2021-05-25 at 4.35.56 PM.png

1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script isn't working

You meant to use the double-equals sign but used single-equals instead.


But actually you shouldn't use double-equals, either. Use the String.equals() method as it has fewer unexpected behaviors. And also use $simple references inside directives, not ${formal} references.

#if( $lead.preferredLocation.equals("Brea") )
<p style="padding: 0; margin: 0;text-align: center;font-weight: bold;">BREA</p>
<span class="Georgia, Times, "Times New Roman", serif;"></span>
<p style="padding: 0; margin: 0;text-align: center;">375 W. Birch Street Suite 1-A</p>
<span class="Georgia, Times, "Times New Roman", serif;"></span>
<p style="padding: 0; margin: 0;text-align: center;">Brea, CA 92821</p>
#end

 

View solution in original post

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity script isn't working

You meant to use the double-equals sign but used single-equals instead.


But actually you shouldn't use double-equals, either. Use the String.equals() method as it has fewer unexpected behaviors. And also use $simple references inside directives, not ${formal} references.

#if( $lead.preferredLocation.equals("Brea") )
<p style="padding: 0; margin: 0;text-align: center;font-weight: bold;">BREA</p>
<span class="Georgia, Times, "Times New Roman", serif;"></span>
<p style="padding: 0; margin: 0;text-align: center;">375 W. Birch Street Suite 1-A</p>
<span class="Georgia, Times, "Times New Roman", serif;"></span>
<p style="padding: 0; margin: 0;text-align: center;">Brea, CA 92821</p>
#end