Custom values using Velocity Scripting | Community
Skip to main content
Monica_Koran
New Participant
February 10, 2020
Question

Custom values using Velocity Scripting

  • February 10, 2020
  • 2 replies
  • 2825 views

I have a campaign in which I am pulling in data values from a SFDC custom object that should render the event date and time the subject is scheduled for. 

However, I only want data values for a certain registrations.  For example if subject registers for a camp session and then registers for an orientation session, I only want to append the orientation session details.  However, because both events are listed in the same custom object, it is appending camp sessions as well.  Any ideas on how I can include only "orientation" sessions in my script?

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

2 replies

SanfordWhiteman
New Participant
February 11, 2020

@monica_koran check responses?

SanfordWhiteman
New Participant
February 10, 2020

This is much the same pattern as in lots of other Community threads: filtering a list of COs down to only those objects that have a property that matches a certain value or is in a list of interesting values.

 

Velocity has a built-in list sorting tool (literally, SortTool). It doesn't have a built-in filtering tool. So you do this in a simple procedural manner. Create a new list, and add the matches to the new list. Then use the new, filtered list going forward.

 

In basic form:

 

#set( $filteredList = [] ) #foreach( $obj in $allObjects_List ) #if( $obj.someInterestingProperty.equals("someInterestingValue") ) #set( $void = $filteredList.add($obj) ) #end #end ## now work with $filteredList

 

Elsa_Man3
New Participant
April 29, 2020

Hi @sanfordwhiteman I came across your solution to this post challenge, which is similar to mine - I'm trying to pull a list of all the Order Names associated with a Contact, if certain conditions for those orders apply (i.e. Status is Processed, and the Program the order came in under matches its SFDC ID). Applying as best I could from your sample code I came up with the below, but in Marketo when I render the email with a test person, it displays empty. Did I apply your sample incorrectly? Let me know if you prefer I create a new post for this question. Thanks as always!

 

#set( $processedOrders = [] ) #foreach ($Program_Order in $Program_Order__cList.get(0).Order_Line_Item__cList) #if( $Program_Order.ProgramOrderStatus.equals("Processed") && $Program_Order.Program.equals("a0A4t0000001YO5EAM")) #set( $void = $processedOrders.add($Program_Order) ) #end #end #foreach( $Program_Order.Name in $processedOrders ) ${Program_Order.Name} #end

 

SanfordWhiteman
New Participant
April 29, 2020

This line doesn't make sense:

 

#foreach ($Program_Order in $Program_Order__cList.get(0).Order_Line_Item__cList)

 

That's referencing the first item in $Program_Order__cList ($Program_Order__cList.get(0)) and assuming it's also a list that can be iterated. That'll never be true in Marketo. If you want to iterate over the list, it's

 

#foreach ($Program_Order in $Program_Order__cList)