Hi,
I am working on velocity scripting where I wanted to achieve particular Serial number from custom object and incase of multiple objects I wanted to keep the warranty extension end date value = 3. I am using below code to achieve this one. I am very new to velocity scripting so please suggest.
Also, you have any docs on Velocity scripting from where I can learn from basic then it would be much helpful.
#foreach($prod in $productActivityList)
#set($prodLOB = $prod.productLOB)
#set($prodCD = $prod.prodActivityCD)
##Calculate Warranty Date
#set( $warrantyEndDate = $convert.toCalendar(
$convert.parseDate(
$prod.warrantyExtensionEndDate,
$ISO8601DateOnly,
$defaultLocale,
$inTimeZone
)
) )
#set( $diffRemaining = $date.difference($calNow,$warrantyEndDate) )
#set( $daysRemaining = $convert.toInteger($diffRemaining.getDays()) )
#if( $daysRemaining == 3 && $eligibleProdList.contains($prodLOB) && $eligibleCDList.contains($prodCD) && !$prod.warrantyExtensionEndDate )
#set($yourMachine = $prod.productBrand)
#set ($serialNo = $productActivityList.get(0).productSerial)
<a href="https://test?upgrade&sn=${serialNo}&source=APOSMAIL&groupId={{lead.storeCodeAffinity}}&CID={{my.CID-Email 02-US}}&rrid={{lead.Midas Contact ID}}">
<img src="#" alt="Extend Your Warranty">
</a>
#end
#end
First, please make sure you use the Syntax Highlighter (Insert/Edit Code Sample) when posting code. You can choose Java as it’s closest to Velocity. I edited your post this time.
Next, with questions like this, you have to completely describe the “shape“ of your Custom Objects — all the relevant field names and data types. We cannot derive that completely from reading your code, especially if the code has errors!
While you work up that more complete description, I’ll with a few immediate questions.
1) Why are you converting from Long to Integer here?
#set( $daysRemaining = $convert.toInteger($diffRemaining.getDays()) )
2) What are you testing for with !$prod.warrantyExtensionEndDate? You already tried to convert that property to a Calendar. If the value can be null, the Calendar object will be null in turn.
#if( $daysRemaining == 3 && $eligibleProdList.contains($prodLOB) && $eligibleCDList.contains($prodCD) && !$prod.warrantyExtensionEndDate )
3) Why are you getting the first (0th) item in the list, as opposed to the current iterator variable $prod?
#set ($serialNo = $productActivityList.get(0).productSerial)
4) You can’t use {{lead.token}} syntax inside Velocity. Use only the Velocity $references for lead fields. And you also can’t include Text {{my.tokens}} inside Velocity. If {{my.CID...}} is also a Velocity token and it’s included earlier in the email, you could set a Velocity $reference inside it to a certain value, then use that $reference in this token
<a href="https://test?upgrade&sn=${serialNo}&source=APOSMAIL&groupId={{lead.storeCodeAffinity}}&CID={{my.CID-Email 02-US}}&rrid={{lead.Midas Contact ID}}">
<img src="#" alt="Extend Your Warranty">
Hi @SanfordWhiteman ,
Thanks for replying !!
1) I changed it to integer because wanted to check the value for 3 days of duration.
2) We are already using smartlist, in that we are putting the qulification criteria of 3 days so not any other will pass out.
3) I wanted to get the serial number of custom object which is falling in this criteria.
We are sending out email to those contacts whose warranty extension date is in future 3 days.
Earlier we have used below URL behind the image where serialNo is email script token but this token was not populating the values of serial number which sits inside of custom object so Marketo Support team suggested to put the image as well as url inside of velocity tokens.
https://test?upgrade&sn=${serialNo}&source=APOSMAIL&groupId={{lead.storeCodeAffinity}}&CID={{my.CID-Email 02-US}}&rrid={{lead.Midas Contact ID}}
what we wanted to achieve is,
Serialno is only velocity token is there, we wanted to populate this number so that we can include this number in the link so that it will automatically fetch the serial number which relates with expiration date.
We wanted to capture particular serial number which will be in 3 days of warranty expiration end date when we have more than 1 objects for a contact.
Your help would be really appreciated. Thanks !!
@SanfordWhiteman
Could you please guide here? how can I achieve the expected value? I tried everything but not getting any proper answer.
1) I changed it to integer because wanted to check the value for 3 days of duration.
But it’s already a Long. Why do you want it to be an Integer? You can compare equality between a Long and Integer just fine. Both sides are cast to Long automatically.
2) We are already using smartlist, in that we are putting the qulification criteria of 3 days so not any other will pass out.
Not sure what that has to do with the question. I had asked why, exactly, you’re checking for Boolean falseness here:
!$prod.warrantyExtensionEndDate
3) I wanted to get the serial number of custom object which is falling in this criteria.
Again, doesn’t seem to answer the question. Why are you assigning a variable to the productSerial property of the first item in the list (.get(0) = index [0] = first item)? Why aren’t you using $prod.productSerial here?
Earlier we have used below URL behind the image where serialNo is email script token but this token was not populating the values of serial number which sits inside of custom object so Marketo Support team suggested to put the image as well as url inside of velocity tokens.
You have to put the entire <a> tag, from start to finish, in Velocity. You can’t do it piecemeal like this: if it’s a link, it has to all come from Velocity. That’s why support said that — it’s true!
Also, the code refers to variables like
$ISO8601DateOnly
Do you have those declared in another token included earlier in the email? You must.