I'm hoping I can use velocity to populate a link instead of using traditional segmentation or creating multiple versions of emails.
I have a link that I need to show, but the link is going to be reliant on the value in a certain field in the lead record.
The value I am using to populate the field is ${lead.creditCardPromoAmount}
What I need it to do is
If $lead.creditCardPromoAmount = 15,000 then display this unique url
elseIf $lead.creditCardPromoAmount = 7,500 then display this unique url
elseIf $lead.creditCardPromoAmount = 5,000 then display this unique url
elseIf $lead.creditCardPromoAmount = 2,500 then display this unique url
Those are the only possible values that members of this program will have.
Solved! Go to Solution.
In general and per my understanding, equals() is more robust than the == operator for comparing data.
#if ($lead.creditCardPromoAmount.equals("15000"))
<a href="https://www.example.com/link1">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("7500"))
<a href="https://www.example.com/link2">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("5000"))
<a href="https://www.example.com/link3">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("2500"))
<a href="https://www.example.com/link4">Account Opening Disclosure</a>
#end
It is recommended to not use the == operator to compare two values because it checks the equality of the reference whereas, the equals function checks the values.
Would something like this work?
#if ( $lead.creditCardPromoAmount == 15000 )
<a href="link1">Account Opening Disclosure</a>
#elseif ( $lead.creditCardPromoAmount == 7500 )
<a href="link2">Account Opening Disclosure</a>
#elseif ( $lead.creditCardPromoAmount == 5000 )
<a href="link3">Account Opening Disclosure</a>
#elseif ( $lead.creditCardPromoAmount == 2500 )
<a href="link4">Account Opening Disclosure</a>
#end
In general and per my understanding, equals() is more robust than the == operator for comparing data.
#if ($lead.creditCardPromoAmount.equals("15000"))
<a href="https://www.example.com/link1">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("7500"))
<a href="https://www.example.com/link2">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("5000"))
<a href="https://www.example.com/link3">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("2500"))
<a href="https://www.example.com/link4">Account Opening Disclosure</a>
#end
It is recommended to not use the == operator to compare two values because it checks the equality of the reference whereas, the equals function checks the values.
Like Darshil says, use .equals(), not ==.
The reason isn't reference equality vs. value equality, though. It's that == type-juggles both sides which can lead to unexpected, even business-incorrect results. .equals() is standard Java, which has predictable, well-documented results.
Ahh - gotcha! Thank you, Sandy! 🙂
Thank you!
So I've updated this token and I'm getting the following result:
But when I preview the email with someone who qualifies, every time I get this result:
I have used the script exactly as outlined (except for adding the unique url for each group):
#if ($lead.creditCardPromoAmount.equals("15000"))
<a href="https://arrow17.secure.cusolutionsgroup.net/files/arrow17/1/file/Interstitials/08%202022%20Visa%20PA_InterstitialDIsc_02.pdf">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("7500"))
<a href="https://arrow17.secure.cusolutionsgroup.net/files/arrow17/1/file/Interstitials/08%202022%20Visa%20PA_InterstitialDIsc_04.pdf">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("5000"))
<a href="https://arrow17.secure.cusolutionsgroup.net/files/arrow17/1/file/Interstitials/08%202022%20Visa%20PA_InterstitialDIsc_06.pdf">Account Opening Disclosure</a>
#elseif ($lead.creditCardPromoAmount.equals("2500"))
<a href="https://arrow17.secure.cusolutionsgroup.net/files/arrow17/1/file/Interstitials/08%202022%20Visa%20PA_InterstitialDIsc_08.pdf">Account Opening Disclosure</a>
#end
And I've made sure the check mark is on the ${lead.creditCardPromoAmount} field.
Any idea why there would be no value displaying?
Well, you do not have a catch-all #else statement in your script, which means that if a person has a value other than the ones mentioned in the #if #elseif conditional statements, they'd not be shown any output (as they'd not qualify for any of the defined conditions). Does your test lead have Credit Card Promo Amount value other than "15000", "7500", "5000", or "2500"? Also, if this is a string field, and if you have "," chars in the value (e.g., "15,000" instead of "15000"), then also it won't work.
I've tested multiple accounts with 1500 and 7500 and got the same result shown above.
Here is the field in a record I attempted: