Velocity script isn't working | Community
Skip to main content
New Participant
May 25, 2021
Solved

Velocity script isn't working

  • May 25, 2021
  • 1 reply
  • 1601 views

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?

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

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

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
May 26, 2021

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