Velocity Snippets #1: Sorts and seeks

Level 10 - Community Moderator
Level 10 - Community Moderator

The idea is for Snippets posts to be code-centric as opposed to blather-centric. Copypasta with minimal commentary let's see how it goes!

ArrayLists in brief

As you advance with Velocity, you'll make heavy use of ArrayLists, that is, arrays of objects.

     ArrayLists are created automatically by Marketo when you access Custom Objects (as <CustomObjectName>List), and you can also create your own using the simple literal syntax you see throughout my code:

#set( $myList = [ 1, 11, 22 ] )

#set( $myOtherList = [


    "id" : 123,

    "prop1" : "apple"



    "id" : 456,

    "prop2" : "orange"


] )

     Sorting ArrayLists by primary properties (think timestamps) and grabbing the most important item are both things you'll want to do — trust me!

Read the full post on TEKNKL :: Blog →​

Level 4

Thanks for this post Sanford Whiteman​. Would you recommend this for trying to only bring back rows with a certain date?

For example, only bring back store numbers who have a date of yesterday.

#foreach $OrderData.Store in $OrderData_cList

#if $OrderData.Date = $yesterday

Load this table



I realize there's some conversion needed to compare string vs dates but we're looking for a 'sort' and only bring back the most recent record. Old stale records are tied to the Contact which we don't want to load.

As always, appreciate the help.

Level 10 - Community Moderator

#foreach( $Store in $OrderData_cList )

#if( $Store.Date.equals($yesterday) )

Load this table



Assuming $yesterday and $Store.Date are both Strings at the time of comparison.

If you have another Q could you post it to Products​ (and link back to this post)?  It's impossible to highlight code here as the editor is limited.