Velocity: Sort Opportunities by date | Community
Skip to main content
Stijn_Heijthuij
Level 6
February 29, 2016
Question

Velocity: Sort Opportunities by date

  • February 29, 2016
  • 2 replies
  • 3920 views

Hi guys,

Is there a way in which you access the last updated opportunity out of multiple open opps through Velocity scripting?

For one of our campaigns we're looking to send out an email when one of the opportunities is updated. We are currently unable select the 'last updated' open opportunity in Velocity scripting.

Result of this is that we're populating information from a random open opportunity instead of a specific (correct) one.

Since the sortTool is not available in Marketo's Velocity scripting I was hoping there would be another way.

Thanks,

Stijn

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

February 29, 2016

Opportunity and Custom Object Lists

When retrieving from Opportunities or Custom Objects, only the ten most recently updated objects of a type are loaded.  These are given as a list, with the name of <objectName>List and are ordered from most to least recently updated record.  So to access the Amount field from the opportunity which was most recently updated, you would use the following:

${OpportunityList.get(0).Amount}

In this example, you reference the OpportunityList object, use the get method to access the record indexed at 0, and then retrieve the Amount property from the returned object.  If you drag a field from an Opportunity or Custom Object into the editor, it will automatically retrieve the field from the record indexed at 0.

July 14, 2016

What If I needed to check multiple items within that most recent opportunity? How would that be set up?

Right now we are stuck using the foreach loop - which is locked at 10 opportunities.

#foreach($opportunity in $OpportunityList)

#if($opportunity.o_opportunity_type == "Home Loan" && $opportunity.o_clear_to_close_date)

     return copy

Basically we want to grab the most recent opportunity that is certain opportunity type, then check for an item within that opportunity. else, look for another piece of information within that opportunity.

Kenny_Elkington
Adobe Employee
Adobe Employee
February 29, 2016

For this specific case you should just use the $TriggerObject.  When you set the campaign up with Opportunity Is Updated as the Trigger, then the updated opportunity will be provided to the script in the $TriggerObject variable.

February 29, 2016

Kenny just beat me to type this message.

$TriggerObject will give 'that updated' opportunity which triggered the event. No need to loop through

Rajesh