SOLVED

Velocity script support - Personalisation tokens from Custom Object entries.

Go to solution
PaddyRR
Level 1

Hello - Thank you for reading. Any support would be very much appreciated. 

 

Background:

We are a housing development business, building and selling plots/houses on housing developments in the UK.

We have a unique, proprietary CRM that is very difficult to influence hence, the seemingly "roundabaout" solution I am about the explain.

 

Solution summary:

When a customer enquired/expresses interest about a housing development, a unique Custom object entry is created in our Marketo instance, linked to the person record. 

PaddyRR_1-1709208708349.png

We would like to personalise a range of emails with contextualised information based on these enquiries. 

Our solution is to use velocity script to populate tokens within a high-level folder, that can then be inherited and utilised within the subsequent emails. 

PaddyRR_2-1709208734826.png

This simple script is essentially, updating the token with the information of that specific development based on the "EnquiryOutletName" field.

 

Issue summary:

This is working great for us! However, there are two key flaws:

1. A customer will often have multiple enquiries linked to their record. Over time, these enquires can be updated so that the "EnquiryOutletStatus:" field shows a value other than "Open". We would like to velocity, to only select an enquiry IF that field equals "Open".

2. When the above update is made, the custom object is updated and brought to the top of the list. it appears that the velocity script is currently selecting the most recently updated entry based on this  "Updated at" field. We would like to stipulate that the script selects the entry with the most recent "EnquiryDate:" field instead. 

 

To summarise the required script criteria, I would like
IF "EnquiryOutletName" equals "XXX", SET tokens as "XXX  IF  "EnquiryOutletStatus:" Equals Open AND  "EnquiryDate:" is the most recent from all entries.

 

The issue is that I do not know, and cannot find, how to write that script correctly. 

I would REALLY appreciate any help to do so!

 

1 ACCEPTED SOLUTION
Jo_Pitts1
Level 10 - Community Advisor

@PaddyRR ,

Here is a consolidated version taking the sorted list approach, and a method of controlling the number of open enquiries to display.

 

 

#set ($maxDevelopmentToDisplay = 2)
#set ($displayCounter = 0)

#set( $allDevelopments = {
  "Westley Green, Langdon Hills" : {
    "Development_Name":"Westley Green",
    "Development_Description":"XXX",
    "Development_Address":"XXX", 
    "Development_Brochure":"XXX", 
    "Development_PageURL":"XXX", 
    "Development_BookingURL":"XXX", 
    "Development_HeaderIMG":"XXX"
  },
  "Meadow View, Silver End" : {
    "Development_Name":"Meadow View",
    "Development_Description":"XXX",
    "Development_Address":"XXX", 
    "Development_Brochure":"XXX", 
    "Development_PageURL":"XXX", 
    "Development_BookingURL":"XXX", 
    "Development_HeaderIMG":"XXX"
  },
  "The Mulberries, Witham":{
    "Development_Name":"The Mulberries",
    "Development_Description":"XXX",
    "Development_Address":"XXX", 
    "Development_Brochure":"XXX", 
    "Development_PageURL":"XXX", 
    "Development_BookingURL":"XXX", 
    "Development_HeaderIMG":"XXX"
  }
  }
)

#set($enquiryListSorted = $sorter.sort($enquiry_cList, ["EnquiryDate:desc"]))

#foreach($enquiry in $enquiryListSorted )
  #if($enquiry.EnquiryOutletStatus.equals("Open"))
    #set($aDevelopment = $allDevelopments[$enquiry.enquiryOutletName] )
    <table>
    <tr>
    <td>Welcome to ${aDevelopment.Development_Name}</td>
    </tr>
    <tr>
    <td>${aDevelopment.Development_Description}</td>
    </tr>
    <tr>
    <td>We're located at:<br>${aDevelopment.Development_Address}</td>
    </tr>
    </table>
    #set ($displayCounter = $math.add($displayCounter ,1))
    #if ( $displayCounter.equals($maxDevelopmentToDisplay) )
      #break
    #end
  #end
#end

 

 

 

Let me know if this suits.

 

Cheers

Jo

View solution in original post

20 REPLIES 20