SOLVED

Re: Weird Issue with Velocity Scripting

Go to solution
Hobie_Thompson1
Level 4

Weird Issue with Velocity Scripting

I have a Velocity script that works in one campaign, but not in another one. I'm racking my brain trying to figure out what the heck is happening here.  There are two different Velocity scripts that are included in the email I am trying to send out. The way the script is supposed to work is off of a data value, lead.SecurityQuizScore. Below, see a screenshot of a test I just did where the Security Quiz Score value is properly computed (meaning my scoring campaign is functioning) to '2':

score.PNG

Here is the part of the HTML code for the email that is going out that contains my Velocity tokens:

html-email.PNG

And here are the two Velocity scripts themselves, contained in the Program in which the email is located:

PercentageLgl:

percentagelgl.PNG

ScriptLgl:

scriptLgl.PNG

Unless I'm missing something, in the above example, the email should load with $imgUrl as the '66percent-250px.png' image and with $testing as 'High'. However, in the email I receive, both of these are set to their fallbacks.

Any idea what is going on here? What am I missing?

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Weird Issue with Velocity Scripting

You have the field checked off in the tree on the right-hand-side of Script Editor, I hope?

Also, default isn't supported with Velocity tokens (choose the default output within the script itself).

Finally, your VTL can be much, much simpler (and thus easier to troubleshoot):

#set( $imgUrl = "http://your.default.image.url/goes/here" )

#set( $scoresToRisk = {

  ["6","12","18"] : "100",

  ["5","11","17"] : "100"

} )

#foreach( $scores in $scoresToRisk.keySet() )

#if( $scores.contains($lead.securityQuizScore) )

#set( $imgUrl = "http://your.image.url/is/${scoresToRisk[$scores]}.png" )

#break

#end

#end

View solution in original post

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Weird Issue with Velocity Scripting

You have the field checked off in the tree on the right-hand-side of Script Editor, I hope?

Also, default isn't supported with Velocity tokens (choose the default output within the script itself).

Finally, your VTL can be much, much simpler (and thus easier to troubleshoot):

#set( $imgUrl = "http://your.default.image.url/goes/here" )

#set( $scoresToRisk = {

  ["6","12","18"] : "100",

  ["5","11","17"] : "100"

} )

#foreach( $scores in $scoresToRisk.keySet() )

#if( $scores.contains($lead.securityQuizScore) )

#set( $imgUrl = "http://your.image.url/is/${scoresToRisk[$scores]}.png" )

#break

#end

#end

Hobie_Thompson1
Level 4

Re: Weird Issue with Velocity Scripting

D'oh! *whaps forehead* I didn't realize the Data Value had to be checked in the Velocity script in order to be used. That solved that problem!

And forgive the sloppy coding! Definitely not my forte.

SanfordWhiteman
Level 10 - Community Moderator

Re: Weird Issue with Velocity Scripting

I didn't realize the Data Value had to be checked in the Velocity script in order to be used. That solved that problem!

Yeah, that's a necessary evil... if all lead fields were automatically exported into Velocity it would be a tragic memory situation.

And forgive the sloppy coding! Definitely not my forte.

Definitely get to know Velocity/Java HashMaps. They'll change the way you write conditions in Velocity: I haven't written a chain of #if-#elseif-#elseifs in ages. In some other environment, they might be overengineering, but Velocity's crazy verbosity makes it essential to find ways to write leaner code. In fact in your conditions above there are a couple of bugs, probably from having data too spread out (see the unreachable code for securityQuizScore 10 and 16).