Velocity Dynamic Content Sorting | Community
Skip to main content
New Participant
May 21, 2020
Solved

Velocity Dynamic Content Sorting

  • May 21, 2020
  • 1 reply
  • 6125 views

I have imported a list of records to custom objects which contains data based on user visits in the website. By using this list trying to create email in Marketo. From CO list, selecting only recent visit of the product. In the given list, have product name, image, URL and recent visit date.

 

Problem- I have created three velocity script and sorting the list based on recent visit date. But, in email output is display incorrect.

 

 

Below three velocity script used for sorting the product name, image and URL.

 

 

 

Script-1 <html> <body> <table> ## start product image select <tbody> #set( $DEFAULT_Product = "No item in list." ) <tr> #if( $pro_cList.isEmpty() ) #set( $outputItemimage = $DEFAULT_Product ) #else #foreach( $pro_c in $sorter.sort($pro_cList, "date:desc") ) #if( !$display.alt($pro_cList["productImage"],"").isEmpty() ) #set( $outputItemimage = $pro_c["productImage"] ) #break #end #end #set( $outputItemimage = $display.alt($outputItemimage, $DEFAULT_Product) ) #end <td> <img width="189" align="right" src="${outputItemimage}" border="0"/> </td> </tr> </tbody> </table> </body> </html>

 

 

 

 

 

Script-2 <html> <body> <table> ## start product name select <tbody> #set( $DEFAULT_Product = "No item in list." ) <tr> #if( $pro_cList.isEmpty() ) #set( $outputName = $DEFAULT_Product ) #else #foreach( $pro_c in $sorter.sort($pro_cList, "date:desc") ) #if( !$display.alt($pro_cList["productName"],"").isEmpty() ) #set( $outputName = $pro_c["productName"] ) #break #end #end #set( $outputName = $display.alt($outputName, $DEFAULT_Product) ) #end <td> ${outputName} </td> </tr> </tbody> </table> </body> </html>

 

 

 

 

 

Script-3 <html> <body> <table> ## start product URL select <tbody> #set( $DEFAULT_Product = "No item in list." ) <tr> #if( $pro_cList.isEmpty() ) #set( $outputItemCTA = $DEFAULT_Product ) #else #foreach( $pro_c in $sorter.sort($pro_cList, "date:desc") ) #if( !$display.alt($pro_cList["productCTA"],"").isEmpty() ) #set( $outputItemCTA = $pro_c["productCTA"] ) #break #end #end #set( $outputItemCTA = $display.alt($outputItemCTA, $DEFAULT_Product) ) #end <td> <a href="${outputItemCTA}">Check out</a> </td> </tr> </tbody> </table> </body> </html>

 

 

 

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

Hi Sanford,

I was wondering  if you have gone through the debug code and please let me know the details.


This line:

#if( !$display.alt($pro_cList["productName"],"").isEmpty() )

 

Should be:

#if( !$display.alt($pro_c["productName"],"").isEmpty() )

 

Remember, when you're iterating over the items ($pro_c) in the list, you want to test the item, not the whole list.

1 reply

SanfordWhiteman
New Participant
May 21, 2020

Hi Jayant,

 

This seems like an overly wordy (and thus fragile) way to do this — it could easily be a single token with a #macro since the logic is the same other than the field name.

 

Beyond that, I'd need to see a dump of all of the data from the list. Chances are, for the fields that are outputting the default value, you don't have them checked off in the tree in Script Editor. 

New Participant
May 22, 2020

Hi San,

Before creating macro, I want to fetch the data for each field correctly. So, I am not able to find checked off condition for the script. Can you please suggest more in this?

 

 

Jay
SanfordWhiteman
New Participant
May 22, 2020

Not sure I understand what you're saying here.  When I say "checked off" I mean in the tree (of Lead and Object fields) on the right-hand-side of Script Editor.