Velocity Snippets #1: Sorts and seeks | Community
Skip to main content
SanfordWhiteman
Level 10
March 28, 2017

Velocity Snippets #1: Sorts and seeks

  • March 28, 2017
  • 2 replies
  • 2672 views

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 →​

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

2 replies

Level 4
April 3, 2018

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

#else

#end

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.

SanfordWhiteman
Level 10
April 3, 2018

#foreach( $Store in $OrderData_cList )

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

Load this table

#else

#end

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.