I want to create a token that populates a field on a custom object "Service Time" each contact could have multiple "service times" so I want to cross reference another field in order to populate the correct "service time"
For example, I want the token to display the "service time" associated with the custom object field "service type" contains "training"
Is this possible with velocity script or some other method?
I want to create a token that populates a field on a custom object "Service Time"
(I think is “is populated with” would be the way to phrase this.)
Is this possible with velocity script or some other method?
Yes, with Velocity.
This logic assumes there’s only one object in the list with a matching value. This is of course not guaranteed by Marketo, but whatever your app is that’s inserting COs may guarantee it.
Thanks, Sanford! Would that look like this?
## Look for Service Appointment Start Times
#foreach ($Service_Appointment_Start_Time__c in ${TASKRAY__Project_Task__cList.get(0)})
## Where Service Type contains Menu
#if (${TASKRAY__Project_Task__cList.get(0).Service_Type__c.contains("menu")})
##Return Start Time
$Service_Appointment_Start_Time__c
#break
#end
#end
Thanks, Sanford! Would that look like this?
Ah, no, that‘s not it. 🙂
I mean the classic Loop-Until-Break pattern in Velocity (as in a lot of languages).
#if( !$yourListOfThings.isEmpty() )
#foreach( $matchableThing in $yourListOfThings )
#if( $matchableThing.yourInterestingProperty.equals("your interesting value") )
#set( $matched = $matchableThing )
#break
#end
#end
#end
Found match: ${matched).