Hello,
Marketo has a new feature that allows you to trigger an action based off of a custom object change. Trigger Off Custom Object Changes - Marketo Docs - Product Docs
I need to populate a triggered email with the custom object data specific to the custom object change. Normally, you can use $!{TriggerObject.CDOField} to populate triggered campaigns, but according to Marketo Support, velocity script does not work with custom object changes at this time. Is there a workaround where I can pull specific fields from the CDO record that triggered the campaign?
Thanks!
Solved! Go to Solution.
You don't need that backwards loop -- that's for reverse()ing an ArrayList based on natural index order.
To sort on updatedAt use SortTool:
#set( $sortedList = $sorter.sort($ObjectList,["updatedAt:desc"]) )
The filter you should do by declaring another ArrayList and populating it (we can't use actual filter predicates like in Java):
#set( $filteredList= [] )
#foreach( $itm in $sortedList)
#if( $itm.Field1 == "Published" )
#set( $tmp = $filteredList.add( $itm ) )
#end
#end
If not surfaced as {{TriggerObject}}, you have to filter the ArrayList (of 10 custom objects) to get the most recently updated based on updatedAt or equivalent timestamp on the object itself.
Hey Sanford,
How would I go about doing that? Can you show some sample code? I would need to sort the ArrayList and also filter based on certain CDO field criteria (i.e. Field1=Published).
I've seen this snippet you wrote for someone else:
I found this very helpful, but would love to see how to edit it to sort by updatedAt and Field1=Published
Thanks!
You don't need that backwards loop -- that's for reverse()ing an ArrayList based on natural index order.
To sort on updatedAt use SortTool:
#set( $sortedList = $sorter.sort($ObjectList,["updatedAt:desc"]) )
The filter you should do by declaring another ArrayList and populating it (we can't use actual filter predicates like in Java):
#set( $filteredList= [] )
#foreach( $itm in $sortedList)
#if( $itm.Field1 == "Published" )
#set( $tmp = $filteredList.add( $itm ) )
#end
#end
Hey Sanford, thank you for your help on this! Greatly appreciated! One last thing, right now with code, when I use $tmp its returning a boolean, true/false value. How would I populate with other fields (i.e. i want to show what's populated in Field3 when Field1 = Published AND Field2 = Google)?
Not sure what you want to "populate" here exactly? The $tmp is just a throwaway variable because Velocity doesn't allow a void (non-value-returning) function call, that is, you can't do
#set( $object.doSomething() )
you have to do
#set( $tmp = $object.doSomething() )
even if you have no use for $tmp.
So all we're doing is calling ArrayList.add().
Sorry for not explaining clear enough.
So i have a CDO for a one to many relationship with multiple fields per record: productName, productID, status, site
I have a triggered campaign to launch when a the status field in the CDO changes. I want it to trigger an email and have it be populated with the specific productName of the record in the CDO that updated, as long as it fits certain criteria (status = Published AND site=Google).
I'm new to Velocity and would love a good base to work off of.
Thanks
In this way Velocity is like most other C-variant languages. When you filter down to the new array, include conditions separated by || or &&.
#if( $itm.Status == "Published" && $itm.site == "Google" )
I was able to get it work. Thank you again for all your help. You are definitely one of the crucial brains to this community! I'm sure I'll be asking more questions that you'll be able to answer very soon!
Good to hear!