Creating a Token To Reference a Specific Field When there are multiple fields | Community
Skip to main content
New Participant
July 6, 2021
Question

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

  • July 6, 2021
  • 1 reply
  • 1850 views

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? 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

1 reply

SanfordWhiteman
New Participant
July 7, 2021

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.

New Participant
July 7, 2021

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
New Participant
July 7, 2021

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