Dear Marketo Community,
We use tokens to generate notification emails for appointment bookings, which pulls from the Opportunities field mapping.
Our issue is that often a contact has multiple opportunities listed against it, and the current scripting logic we have is always pulling the "latest" opportunity linked to the contact - I believe this is associated with the get(0) function in the Velocity script.
The end result is that our customers are getting notifications for appointment bookings which is pulling reference information that is from the wrong opportunity (usually due to a cancelled or rescheduled booking)
Token examples
${display.alt($OpportunityList.get(0).sourceJobNumber,"")}
${OpportunityList.get(0).Stage}
Is anyone aware of how to add a qualifier to the velocity script such that we can refine the criteria of how the token is being populated? We don't necessarily want the "latest", we want to specify criteria on how to match the Opportunity needed, in our case show the Job Number which has Opportunity Stage = "Confirmed". I imagine it's a combination of specifying this in the velocity script, but can't work it out.
Thanks for any pointers or suggested solutions for this challenge, we were thinking it may be a relatively common challenge, but could not find any mention of it.
Many thanks,
Scott
Loop over the list of Opportunities, compare the property value. Search for my posts that include the #foreach operator -- there are tons of examples of matching items in the list.
Also pls highlight your code using the Syntax Highlighter (choose Java from the drop-down as it's closest to Velocity).
Weird, we received some helpful comments from Sanford for this post, then I edited the original post, but his comments disappeared, maybe a moderators approval step involved. I'll say thank you here, it worked, and I will post the solution here.
Just sharing our implementation, it was a relatively simple coding solution now that we see how #foreach works. I'll say it again, thanks Sanford Whiteman
#foreach($list in ${OpportunityList})
#if($list.Stage=="Booked")
<html>
<body>
Job Reference Number: $list.sourceJobNumber </br>
Car Registration Number: $list.vehicleRego</br>
Date: $list.appointmentWindowStartDayText</br>
Time: $list.appointmentWindowStartTimeText</br>
Address: $list.serviceAddress</br></br></br>
</body>
</html>
#end
#end
Thanks for sharing, Scott! Two things though...
Great to note, we'll follow this recommendation, many thanks.