Creating a Token To Reference a Specific Field When there are multiple fields

kolbenpreble
Level 1

Creating a Token To Reference a Specific Field When there are multiple fields

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? 

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Creating a Token To Reference a Specific Field When there are multiple fields


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.

 

  • loop (#foreach) over the Custom Object List
  • check the current CO to see if its property value matches your interesting property value
  • when you find a matching object, output it and #break
  • otherwise, let Velocity continue to the next turn of the loop

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.

kolbenpreble
Level 1

Re: Creating a Token To Reference a Specific Field When there are multiple fields

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

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Creating a Token To Reference a Specific Field When there are multiple fields


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).