Fetch Opportunity owner in Email Script token

MACTSI
Level 1

Fetch Opportunity owner in Email Script token

Hi there,

I am trying to fetch the opportunity owner from opportunities tied to a person record in Marketo Database. I am trying to use Velocity but it is not working for me. Can someone let me know what am I doing wrong?

#set( $opportunity = $lead.Opportunity )
#if( $opportunity && $opportunity.OpportunityOwnerName && $opportunity.OpportunityOwnerName != "")
    Opportunity Owner Name: $opportunity.OpportunityOwnerName
#else
    Opportunity Owner Name: Not available
#end

 

1 REPLY 1
SanfordWhiteman
Level 10 - Community Moderator

Re: Fetch Opportunity owner in Email Script token

You seem to be guessing at property names, which is quite strange? When you drag a field onto the Script Editor canvas, you always know the exact Velocity property name, so I don’t know where you’re coming up with this code.

 

There’s no property of the $lead called Opportunity that’s a simple object. That wouldn’t make sense because Lead:Opportunity is a one:many relationship.

 

The correct object is $OpportunityList. It’s not a property of the $lead, and it’s a List, not an object/Map, because of the many:one.

 

You can iterate over all the opportunities and their checked-off fields like this:

#if( !$OpportunityList.isEmpty() )
  #foreach( $oppty in $OpportunityList )
    #foreach( $key in $oppty.keySet() )
      $key $oppty[$key].class $oppty[$key]
    #end
  #end
#end