Velocity scripts - using custom objects in email

Anonymous
Not applicable

Velocity scripts - using custom objects in email

Howdy Marketo gurus ...

Is anyone using Velocity scripts in combination with custom objects mapped into Marketo from Salesforce to do advanced personalization in email?

I have a case where custom object A (a list) is related to custom object B via a key (or "Relationship Field").  For each item in the list, I want to access the name of the item.  In Velocity, referencing $A__cList.get($index).Name gives me the key.  I would expect something like $A__cList.get(Index).B__cList.get(0).Name to get me the actual name. 

Records in A have a one-to-many relationship with records in B.  That is, each record in A maps to one record in B, but each record in B can map to multiple records in A.

Ultimately, I'm trying to reference A.B.Name, but I'm only having success referencing A.Name.  A.Name gives me a Salesforce unique identifier that doesn't make for a very friendly "label" to use in an email message.  Both A and B are enabled under the Object Sync area of our Salesforce integration (in the admin section).

I know that wading into the specifics of someone else's script may not be your idea of fun on a Tuesday night ... I would welcome any examples of complicated custom object references that are working for you in Marketo Velocity scripts. I'd also love to swap script examples and templates offline for anyone who has used Velocity extensively in Marketo - Googling around gets me lots of manuals and Stackoverflow threads, but nothing that is specific to what folks are actually trying to do in Marketo.

Thanks,
-patrick
Tags (1)
2 REPLIES 2
Anonymous
Not applicable

Re: Velocity scripts - using custom objects in email

[Update based on related support case]

Apparently, it is not possible to reference objects that do not hang directly off the lead record in Marketo's email script tokens (using a Velocity script).  Even though all custom objects are visible in the email script editor, they are not actually all available.

Marketo has labeled this a "bug".  I would propose that the "fix" is to make any custom objects that are related to lead records, even those that hang indirectly off the lead record (e.g. A.B.Name or A.B.C.Name) accessible for scripting purposes. 

Unfortunately, the "quick and easy" (and less helpful) fix is to just remove custom objects that are not currently referenceable from the email script editor GUI.

-patrick
Phillip_Wild
Level 10

Re: Velocity scripts - using custom objects in email

Hi Patrick

I'm not sure if the answer below is still correct - but I've found I can only reference "first level" custom object fields through the scripting. We have a very similar situation to you, and the solution was to expose the field we want on the first level object so we can access it.

One word of warning - you will need to trick Marketo into thinking the new field has been "modified" in Salesforce in order for it to sync all the records over. Otherwise, it will only sync the new field where it sees an update to it - which will be any changes made after you create the field.

Here is some code I've had some luck with so far:

To get evaluation scores

<ul>

#foreach ($EvaluationScore in ${Tour_Evaluation__cList})

<li>${EvaluationScore.NPS_Rating__c}

</li>

#end

This returns the numbers in a list format - eg.

* 10

* 7

* 5

To return a first level object from a field

<ul>
#foreach ($srv in ${TravellerServices__cList})

<li>
${srv.ServiceTypeTS__c}
    </li>   
#end

</ul>

This returns ServiceTypeTS in list format - eg.

* Hotel

* Car

* Tour

To get total purchases and their codes based on an IF statement

#set ($NumberofPurchases = 0)

<ul>

#foreach ($srv in ${Purchases__cList})

    #if (${srv.ServiceTypeTS__c} == "Paint")

    <li>

    ${srv.Service_Paint_Name__c}

     </li> 

       #set ($NumberofPurchases = $NumberofPurchases +1)

    #end

#end

</ul>

Number of Purchases = $NumberofPurchases

This return a bulleted list of purchases, followed by the total number:

* Red

* Blue

* Green

Number of Purchases = 3

I hope this helps. Have a look at my question if you can, hopefully we can help each other! Velocity email scripting - sorting a list

Phil