velocity scripting for fetching the data from custom object | Community
Skip to main content
New Participant
January 7, 2022
Question

velocity scripting for fetching the data from custom object

  • January 7, 2022
  • 1 reply
  • 3072 views

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

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
New Participant
January 7, 2022

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">

 

 

 

New Participant
January 7, 2022

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 !!

New Participant
January 10, 2022

@sanfordwhiteman 

Could you please guide here? how can I achieve the expected value? I tried everything but not getting any proper answer.