Custom values using Velocity Scripting

Monica_Koran
Level 3

Custom values using Velocity Scripting

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?

4 REPLIES 4
SanfordWhiteman
Level 10 - Community Moderator

Re: Custom values using Velocity Scripting

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
Level 2

Re: Custom values using Velocity Scripting

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
Level 10 - Community Moderator

Re: Custom values using Velocity Scripting

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)

 

SanfordWhiteman
Level 10 - Community Moderator

Re: Custom values using Velocity Scripting

@Monica_Koran check responses?