Re: Velocity Scripting Accessing all custom objects in a single event

Angus_McCann1
Level 3

Velocity Scripting Accessing all custom objects in a single event

In our instance in Marketo, we store purchased items inside of Custom Objects.

For some of the objects (we call Webinar Entitlements) we sent out a "Here is how to access your webinar" email that uses velocity scripting to pull the information from inside the Custom Object and populate it into the email. The email is triggered on the "Added to Custom Object" event, with a few additional constraints around the information inside the custom object.

The problem we have is that the scripting is strictly taking a value - we aren't using loops or conditionals and calling out the index position. So if someone purchases say, 3 webinars in one check-out, they will get 3 emails all with the information specific to the custom object in that 0 index position. 

I'm working out with developers a way to send ONE email only populated with webinar information that they purchased that day / that singular check-out event. There is a way we can use conditionals and loops, however, our developers are asking if there is a way we simplify the script and access ONLY the objects of the event and populate based on event. So say I purchased 3 webinars in 2019. And on Jan 1 2020 I purchased 2 webinars in one check-out event. How would I go about writing the velocity scripting so the email only includes the custom objects added to my record on Jan 1. Is there a token that I can reference that pulls all entitlements added for that event of adding multiple custom objects?

Further, it would need to account for mixed media. Say I buy 1 book and 2 webinars - we would want to script to ONLY pull info from the Webinar Entitlement and exclude information from the "Book Entitlement".

3 REPLIES 3
SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting Accessing all custom objects in a single event

$TriggerObject is the record in the list that triggered a Smart Campaign -- naturally this cannot apply to a batch SC, and it only applies to one event record at a time (just like all triggers).

So this is a built-in way to focus only on the interesting object.

In a batch context, you'll have to find your focused object(s) using a date filter, there wouldn't be any other way to know which ones are "today's" updates.

Angus_McCann1
Level 3

Re: Velocity Scripting Accessing all custom objects in a single event

What I was thinking of doing was just having the schedule tab only allow someone to go through the smart campaign (SL: Trigger-Added to CO | Flow: Send Email) once every 0.5hr, so if someone purchased 3 items at once / had three custom objects added at 12:00pm, they would only get 1 email with a script that pulls all 3 items, rather than 3 emails each with the same/index = 0 object.

Correct me if I'm misunderstanding your response - what I'm hearing is that using a trigger is inherently a 1:1 so unless we are using a batch campaign (which we won't - this is a "transactional" email that we want deployed instantly) we'd need to write in for loops and conditionals ($entitlement.purchaseDate = today && $entitlement.entitlementType = webinar) into the Velocity Script to pull out specifically which custom objects we want to populate into a single trigger-based email?

SanfordWhiteman
Level 10 - Community Moderator

Re: Velocity Scripting Accessing all custom objects in a single event

What I was thinking of doing was just having the schedule tab only allow someone to go through the smart campaign (SL: Trigger-Added to CO | Flow: Send Email) once every 0.5hr, so if someone purchased 3 items at once / had three custom objects added at 12:00pm, they would only get 1 email with a script that pulls all 3 items, rather than 3 emails each with the same/index = 0 object.

If your objects are only added in batches every half-hour, that’s a good theory. But you would actually want the schedule window to be slightly larger than the batch upload window, since in trying to align them perfectly you might end up getting no results at all! (Your clocks would have to be perfectly synced, all but impossible.)

... so unless we are using a batch campaign (which we won't - this is a "transactional" email that we want deployed instantly) we'd need to write in for loops and conditionals ($entitlement.purchaseDate = today && $entitlement.entitlementType = webinar) into the Velocity Script to pull out specifically which custom objects we want to populate into a single trigger-based email?

Correct.