Guide to Sorting and Referencing Custom Objects in Marketo
In Marketo Engage, you can reference parent and child custom objects that are directly connected to the Lead or Contact. However, third-level custom objects are not accessible in this manner. This ability is crucial for personalizing your marketing efforts, allowing you to leverage data specific to your leads and contacts.
For each custom object, you can access the 10 most recently updated records per person or contact. These records are ordered from the most recently updated (position 0) to the oldest updated (position 9). This ordering ensures that you are working with the freshest data available, which is essential for timely and relevant marketing communication.
Referencing Custom Objects Based on Specific Fields
While the default behavior is to access the most recently updated records, you can also reference specific records by sorting the custom object based on a particular field. This capability allows for more tailored and precise data manipulation.
To achieve this, you can use the sort tool of the Velocity scripting language. However, there are some important considerations, or "gotchas," to be aware of when sorting with Velocity:
Key Considerations for Sorting with Velocity
Case-Insensitive Sort for Strings:
Velocity treats strings case-insensitively. For example, "abc" and "Abc" are considered identical. This behavior can impact your sort results if your data contains strings that only differ by case.
Date Strings in
yyyy-MM-dd
Format:Date strings in the
yyyy-MM-dd
format can be sorted without conversion because they are designed to alphabetize properly. This makes it straightforward to sort records by date when using this format.
ISO Datetime Strings:
ISO datetime strings (
yyyy-MM-ddTHH:mm:ssZ
) and similar formats (e.g.,yyyy-MM-dd HH:mm:ss
) also sort correctly without conversion. This allows for easy sorting of datetime fields.
Localized Date Strings:
Localized date strings (e.g., "December 1, 2016") require conversion to actual date objects before sorting. A simple alphabetical sort will not work correctly for these formats. To sort these strings, you must:
Loop over the
$objList
to add a new Date property to each object.Use the
Date
property for sorting, e.g.,$sorter.sort($objList,"trueDate:desc")
.
Example
To illustrate, let's say you have a custom object with a date field in the yyyy-MM-dd
format. You can directly sort and reference the records as follows:
#set( $sortedList = $sorter.sort($customObjList, "dateField:desc") ) #set( $recentRecord = $sortedList[0] )
However, if your date field is in a localized format, you need to convert it first:
#foreach( $obj in $customObjList ) #set( $obj.trueDate = $convert.toDate($obj.localizedDate, "MMMM d, yyyy") ) #end
#set( $sortedList = $sorter.sort($customObjList, "trueDate:desc") ) #set( $recentRecord = $sortedList[0] )
Conclusion
Understanding and effectively utilizing custom object references in Marketo can significantly enhance your data management and email personalization capabilities. By leveraging the sort functionalities and keeping the key considerations in mind, you can ensure accurate and efficient data handling, enabling more personalized and impactful marketing emails.