Hi Everyone -
I've been a Marketo User for years, but this is my first post in here, so my sincerest apologies if I'm posting in the wrong place. I was wondering if anyone has ever used Velocity scripting to evaluate greater than or less than statements using velocity scripting. For example, I'd like to display a phrase x if a person most recently has a currency value of x1, but phrase y if they have a currency value if y1. I think I'm running into the issue that I'm evaluating greater than or less than currency values against integers, but for the life of me I can't figure out how to use the Number Tool to convert a stored currency value to an integer. Sample code is highlighted below. Any help would be greatly appreciated!
#set ( $d = "$")
#set ( $MRC = ${lead.recentDollarAmount} )
#if( $MRC > 1001 )
<strong>Phrase 1</strong>
#elseif( $MRC > 499 && $MRC < 1001)
<strong>Phrase 2</strong>
#elseif( $MRC > 99 && $MRC < 501)
<strong>Phrase 3</strong>
#elseif( $MRC > 49 && $MRC < 101)
<strong>Phrase 4</strong>
#elseif( $MRC > 4 && $MRC < 11)
<strong>Phrase 5</strong>
#else
<strong>Phrase 6</strong>
#end
There's no problem comparing Floats with Integers*: widening conversion takes care of that.
The question is whether your $lead.recentDollarAmount is actually a Float. Something tells me it's a String. Which means you want
#set ( $MRC = $convert.toDouble($lead.recentDollarAmount) )
You also don't need the separate variable $d, as $esc.d already exists for the literal dollar sign.
* except for the inherent problem of using Floats at all
Thanks Sandy! Much appreciated. It worked in preview when I personalized it to myself, but when I tried to send a personalized sample, I got this error:
Invocation of method 'toDouble' in class org.apache.velocity.tools.generic.ConversionTool threw exception java.lang.NullPointerException near
Do you know what I'm doing wrong?
William
You have to use a real email, not a sample, to test Velocity.