I think the issue is that it's reading ${lead.previous_billing_period_previews} as a string instead of as a number, so that's why nothing is triggering the if statement, but I don't know how to switch it to a number in velocity script.
Here's what I've got:
#set( $preview = $number.integer(${lead.previous_billing_period_previews}) )
#if( ${lead.previous_billing_period_previews} > 1000 )
at $preview,
#else
nearing your previews limit,
#end
So if someone has more than 1000 previews it should display their previews, but instead it's always displaying "nearing your previews limit" I've tried several different variations, but haven't found anything that works. Any help would be welcome.
Solved! Go to Solution.
#set( $previews = $convert.toInteger( $lead.previous_billing_period_previews ) )
#if( $previews > 1000 )
at ${previews},
#else
nearing your previews limit,
#end
This mostly works, I still need the preview to be a string when I display it
There's no difference between (a) stringifying a Number first and (b) outputting a Number directly in Velocity. It's always converted to a String upon output.
when the value of $lead.previous_billing_period_previews is null, then I get an error message.
It's never null, but an empty String, which is extremely different. And null isn't a valid keyword in Velocity, so your code above will have a fatal error.
If you need to account for the empty case, then check for it explicitly.
#if( $lead.previous_billing_period_previews.isEmpty() )
#set( $previews = 0 )
#else
#set( $previews = $convert.toInteger( $lead.previous_billing_period_previews ) )
#end
#if( $previews > 1000 )
at ${previews},
#else
nearing your previews limit,
#end
#set( $previews = $convert.toInteger( $lead.previous_billing_period_previews ) )
#if( $previews > 1000 )
at ${previews},
#else
nearing your previews limit,
#end
This mostly works, I still need the preview to be a string when I display it and when the value of $lead.previous_billing_period_previews is null, then I get an error message. So I need to set up something to deal with those values. I'm doing something wrong, but I'm not sure what.
#set( $preview = $number.integer($lead.previous_billing_period_previews) )
#if( $lead.previous_billing_period_previews === null )
#set ( $previewInt = 0 )
#else
#set( $previewInt = $convert.toInteger($lead.previous_billing_period_previews) )
#end
#if( $previewInt > 1000 )
at ${preview},
#else
nearing your previews limit,
#end
This mostly works, I still need the preview to be a string when I display it
There's no difference between (a) stringifying a Number first and (b) outputting a Number directly in Velocity. It's always converted to a String upon output.
when the value of $lead.previous_billing_period_previews is null, then I get an error message.
It's never null, but an empty String, which is extremely different. And null isn't a valid keyword in Velocity, so your code above will have a fatal error.
If you need to account for the empty case, then check for it explicitly.
#if( $lead.previous_billing_period_previews.isEmpty() )
#set( $previews = 0 )
#else
#set( $previews = $convert.toInteger( $lead.previous_billing_period_previews ) )
#end
#if( $previews > 1000 )
at ${previews},
#else
nearing your previews limit,
#end
Thank you. I do need to include the number.integer as that's how I get the comma to display in the number. But the isEmpty() is what I needed.
OK. Just to be clear or for any lurkers, $number.integer outputs a formatted String with a preset NumberFormat.
But simply outputting an Integer ${variable} also creates a String!
(There's no way to "output" an Integer variable into the body of a Text/HTML email as an Integer, as it's a text-only format. It's always a String representation of the Integer.)