Email Script for Opportunity List

Lucho_Soto
Level 5

Email Script for Opportunity List

We're trying to use Email Scripts for the first time and are running into some difficulties. We're trying to use this for an shipping info request email, which would run as a batch every week day for opportunities closed that day. We want a list of the Closed-Won opportunities for that customer on that day to show up in the email. So far, my code looks like this:

${OpportunityList.get(0).CloseDate} ${OpportunityList.get(0).oOpportunityFSID}

I know that isn't enough for my specific parameters, but I expected a list of all closed opps to show up. However, it is only pulling the first opp from the Opportunity tab, even though the lead I'm using for the sample email has 7 opps (6 Closed-Won), many of which are more recent than the one that's showing up in the email.

What would my code need to look like to make this campaign possible?
Tags (1)
6 REPLIES 6
Kenny_Elkington
Marketo Employee

Re: Email Script for Opportunity List

Hi Lucho,

You'll need to loop through the OpportunityList.  Right now, you're only getting the values from the Opp indexed at 0 in the array.  It would look something like this:

#foreach ( $opportunity in $OpportunityList)
     $opportunity.CloseDate
     $opportunity.oOpportunityFSID
Anonymous
Not applicable

Re: Email Script for Opportunity List

I'm running into this same issue. If I build the #foreach loop such as:

#foreach ( $opportunity in $OpportunityList)

     $opportunity.CloseDate

     $opportunity.oOpportunityFSID

#end

and if there are 3 opportunities with the first opportunity having a close date of 2015-01-5 and an FSID of 005xxx, the result is:

2014-01-05 005xxx 2014-01-05 005xxx 2014-01-05 005xxx

The docs (Email Scripting » Marketo Developers ) show this being nice and easy:

  1. #foreach( $event in $EventsList )
  2.     #set ( $year = ${event.date.split("-").get(0)} )
  3.       
  4.     #if ( $year == "2013" )
  5.       #set ( $EventsThisYear = $EventsThisYear + 1 )
  6.       <tr>
  7.         <td><ahref="http://ratingwebsite.com/?event=$event.id">$event.name</a></td>
  8.         <td>$event.location</td>
  9.         <td>$date.format('MMMM d yyyy', ${convert.parseDate($event.date, 'yyyy-MM-dd')})</td>
  10.       </tr>
  11.     #end
  12.   #end

Now, for the opportunity example, you don't really need the math element, so:

  1. #foreach( $event in $EventsList )
  2.           <tr>
  3.         <td><ahref="http://ratingwebsite.com/?event=$event.id">$event.name</a></td>
  4.         <td>$event.location</td>
  5.         <td>$date.format('MMMM d yyyy', ${convert.parseDate($event.date, 'yyyy-MM-dd')})</td>
  6.       </tr>
  7. #end

This offers the same repetitive result, returning only the first result multiple times. Is the #if statement required for this to be successful? What am I missing?

Anonymous
Not applicable

Re: Email Script for Opportunity List

Here are the Velocity script docs for Kenny's implementation:
http://people.apache.org/~henning/velocity/html/ch05s04.html
Anonymous
Not applicable

Re: Email Script for Opportunity List

The link is dead - could you please repost? It sounds like the answer to a problem i've got a the moment!
Anonymous
Not applicable

Re: Email Script for Opportunity List

I don't have a link to the docs, but if you want to describe your problem, I might be able to help. I've written a few email scripts around extracting opportunity info.

Anonymous
Not applicable

Re: Email Script for Opportunity List

got a script to pull the most recent opportunity date ? We are trying to pull just the most recent opportunity for a particular script, but are stuck so to speak (the script takes the opportunity at the bottom of the opportunity list in marketo, which would be the oldest.

This is the script thus far, we are just missing a bit of code to specify most recent

#foreach($opportunity in $OpportunityList)

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

  ${OpportunityList.get(0).Name}

        #break

            #end#end