Velocity: Sort Opportunities by date

Highlighted

Velocity: Sort Opportunities by date

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

6 REPLIES 6
Highlighted
Anonymous
Not applicable

Re: Velocity: Sort Opportunities by date

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.

Highlighted
Anonymous
Not applicable

Re: Velocity: Sort Opportunities by date

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.

Highlighted
Marketo Employee

Re: Velocity: Sort Opportunities by date

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.

Highlighted
Anonymous
Not applicable

Re: Velocity: Sort Opportunities by date

Kenny just beat me to type this message.

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

Rajesh

Highlighted
Level 4

Re: Velocity: Sort Opportunities by date

Thanks, Kenny Elkington​. Does this work as well for Marketo custom objects?

We have restaurant store data which gets upserted into a custom object. We want to #foreach loop through and only pull back those that have an Order_Date of yesterday. The issue we're seeing is old rows from months ago are displaying since it was the first created record (and we're not using .get(0)).

Any ideas on how we can prevent old rows from displaying while still allowing multiple with yesterday's date to display?

Highlighted
Level 10 - Community Moderator

Re: Velocity: Sort Opportunities by date