AnsweredAssumed Answered

Sorting a Marketo Custom Object with Velocity

Question asked by Wyatt Bales on Apr 9, 2018
Latest reply on Apr 10, 2018 by Wyatt Bales

This topic has been briefly touched on a few other threads (e.g. Velocity Snippets #1: Sorts and seeks) with Sanford Whiteman but hoping to further clarify.

 

Use Case: Display a table for each store locations' order data if the store's order data is yesterday.

Design: API upsert into Marketo Custom Object with triggered smart campaign which fires email

Issue: Sometimes a franchise owner may sell a store an no longer be upserted into Marketo. Thus, old order data will live in the custom object. Our #foreach loop will bring back the oldest record instead of the custom object row which was updated.

 

I realize from Kenny Elkington's response (Velocity: Sort Opportunities by date), you can use $TriggerObject but we still need to load multiple rows instead of just the most recently updated. Therefore I believe a #foreach loop is still needed.

 

I understand the .get(0) finds the first/oldest row in the custom object so we've dropped that but still looking for a way to sort and/or only load rows which have an order date = yesterday.

 

Appreciate the help and please forgive my lack of Velocity understanding.

 

 

#foreach (${mcDonaldsOrderSummaryV2_c.storeNumber} in ${mcDonaldsOrderSummaryV2_cList})

##CONVERT CUSTOM OBJECT STRING DATE TO DATE FOR COMPARISON
#set ($OrderDate = ${mcDonaldsOrderSummaryV2_cList.get(0).dateOfOrder})
#set ($parsedOrderDate = $convert.parseDate($OrderDate, "yyyy-MM-dd"))

##SET LOCAL VARIABLE FOR A YESTERDAYS DATE
#set ($TodaysDate = $date)
#set ($formattedTodaysDate = $date.format("yyyy-MM-dd", $TodaysDate))

#set ($dayago = $date.calendar)
$dayago.add(5,-1)
##A Week Ago's Date: $date.format('yyyy-MM-dd', $dayago.time)<br>

##SET LOCAL VARIABLE WHICH IS THE DIFFERENCE BETWEEN ORDER DATE AND A WEEK AGO
#set ($dateDifference = $date.difference($parsedOrderDate, $dayago).getDays())

##IF THE ORDER DATE IS GREATER THAN OR LESS THAN A DAY, DON'T BRING IT BACK
#if ($dateDifference > 2)
#elseif ($dateDifference <= 2)

Outcomes