Displaying Account Owner info if it’s present, and Person Owner info if not (using Velocity)

Level 10 - Community Moderator

Some folks in your Marketo database have an Account Owner, some have a Person (i.e. CRM Contact-level) Owner, and some aren’t yet owned.

 

So how do you include the best-fit owner info — Account-level first, then Contact-level as a fallback — in an email?

 

One code-free way might be to use a Dynamic Snippet, tied to a Segmentation with non-empty Account Owner as the highest priority Segment. But this would consume one of your precious 20 Segmentations, so I don’t recommend it.

 

Far more lightweight is using a Velocity {{my.token}}. VTL can easily detect whether Account-level stuff exists or not (note in this case, nonexistent means an empty String rather than an explicit null) and output accordingly.

 

Here’s all you need:

## @requires-tokens
##  [none]
##
## @requires-objects
##   Person ($lead)
##
## @requires-object-fields
##   Person.Account Owner Email Address (Account_Owner_Email_Address)
##   Person.Account Owner First Name (Account_Owner_First_Name)
##   Person.Account Owner Last Name (Account_Owner_Last_Name)
##   Person.Sales Owner Email Address (Lead_Owner_Email_Address)
##   Person.Sales Owner First Name (Lead_Owner_First_Name)
##   Person.Sales Owner Last Name (Lead_Owner_Last_Name)
##
## prefer Account_* info to Sales_*
#if( !$lead.Account_Owner_Email_Address.isEmpty() )
Owned at Account level by ${lead.Account_Owner_First_Name} ${lead.Account_Owner_Last_Name} <${lead.Account_Owner_Email_Address}>
#elseif( !$lead.Lead_Owner_Email_Address.isEmpty() )
Owned at Person level by ${lead.Lead_Owner_First_Name} ${lead.Lead_Owner_Last_Name} <${lead.Lead_Owner_Email_Address}>
#else
I'm not owned! I'm not owned!
#end

 

Make sure all the fields in @requires-object-fields are checked off in Script Editor. (More about  @annotations in an upcoming post.)

 

Note the use of &lt; and &gt; to HTML-escape the < and > symbols around the email address.* That also indicates this code is for the HTML part of an email: in the Text part, you would use literal <>.

 


Notes

* If I didn’t trust the data, all the output would be wrapped in $esc.html(). Since owner data is controlled by your company, it’s a safe assumption that ~99.999% of the values won’t need escaping. Writing bulletproof Velocity involves a lot more escaping/encoding than most people realize... but doing it right also makes the language more intimidating, so I’ll refrain from it here.