I Broke My Adapted Velocity Scripts | Community
Skip to main content
Liz_Davalos
New Participant
January 4, 2018
Solved

I Broke My Adapted Velocity Scripts

  • January 4, 2018
  • 1 reply
  • 3046 views

First I'll say I've already received significant help from many people here on getting my toes wet in velocity scripting. Here's some I adapted for my purposes (that other's shared) and I somehow broke:

The point of this is to only show the token data if they have a city in the system:

#if( !$lead.City.isEmpty() && !$lead.Inferred_City.isEmpty() )

   #set ($nearlocation = "")

#elseif ( !$lead.City.isEmpty() )

#set ($nearlocation = " Near ${lead.Inferred_City}")

#else

#set ($nearlocation = " Near ${lead.City}")

#end

${nearlocation}

This token is for a sentence that either ends with their first name (if we have it) or just ends.

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

  #set ($greeting = "")

#else

  #set ($greeting = " ${lead.FirstName}")

#end

${greeting}

Thank you, thank you, thank you, to anyone who can help me solve this, ETA 10ish days total now working with Velocity Scripts.

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 Liz_Davalos

Yes, the boxes are checked (although I didn't know that was required so helpful for the future). I just edited my question so it should show as code now.

1 reply

SanfordWhiteman
New Participant
January 4, 2018

Have you ensured that the fields you're using checked off in the tree on the right-hand-side of Script Editor?

Also, please highlight your Velocity snippets as Java using the Advanced Editor's Syntax Highlighter. Otherwise code is very difficult to read.

Liz_Davalos
Liz_DavalosAuthorAccepted solution
New Participant
January 4, 2018

Yes, the boxes are checked (although I didn't know that was required so helpful for the future). I just edited my question so it should show as code now.

SanfordWhiteman
New Participant
January 4, 2018

Yes, it is required so the fields will be present in the Velocity context.

While your code looks runnable, I wonder about your logic here:

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

This means "If the statement First Name is empty is not true..." -- in other words, "If First Name is not empty..."

Yet when this condition matches, you're setting the greeting to the empty string.

Are you sure you don't have this backwards?