Does Velocity Scripting Support JSON Field | Community
Skip to main content
January 29, 2016
Solved

Does Velocity Scripting Support JSON Field

  • January 29, 2016
  • 2 replies
  • 3699 views

Does velocity scripting for email support a json attribute. I am thinking of creating a custom object, called "Custom Event", then having a field in that custom event with a stingified json payload. Can I use velocity to serialize that string into json and then reference specific attributes of that object for the email tokens?

Thanks!

Related Threads:
Re: Velocity Scripts - Integrating Data From An External Database

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

I've seen similar things done just by using a text field, and then picking a delimiter and mapping each possible field to a particular array index.  So for example, you have these fields in your virtual object:

First Name

Last Name

Company

You would then serialize it with your selected delimiter like so:

Kenny|Elkington|Marketo

As long as you're serializing uniformly and always have the same indexes for fields, then you can get this:

#set($objectFieldArray = $myObjectList.get(0).split("|"))
#set($firstName = $objectFieldArray[0])

#set($lastName = $objectFieldArray[1])

#set($company = $objectFieldArray[2])

This will work for any type of flat record, but can be troublesome for objects with additional depth.

2 replies

February 2, 2016

Kenny Elkington​ Since Velocity seems to support XML, have you seen people do this with XML instead of JSON. In addition do you happen to know when Marketo references

You can reference first and second level custom objects that are directly connected to the Lead or Contact, but not third-level custom objects.

Does this mean if a Lead has many Opportunities, and those opportunities have many Proposals... is Lead considered top level, and opportunities 2nd level? Would proposals be 3rd level?

Also what is the max length by default on a string on a custom obejct? Is this changeable by support?

Thanks!

Kenny_Elkington
New Participant
February 2, 2016

I have not seen anyone use XML for this with velocity, but we do not enable the XML tool in Marketo, so I think it would be a similarly tough scenario to JSON.

>Does this mean if a Lead has many Opportunities, and those opportunities have many Proposals... is Lead considered top level, and opportunities 2nd level? Would proposals be 3rd level?

You can't link to custom objects through opportunities in Marketo, so this isn't applicable here.

>Also what is the max length by default on a string on a custom obejct? Is this changeable by support?

Strings are 255, Text is 2000, and Text Area is 30000, none of the lengths are alterable.

Kenny_Elkington
New Participant
January 29, 2016

This isn't something that velocity is good at.​  What exactly is keeping you from just defining this in your object schema?

January 29, 2016

The reason is because I am using a custom object as generic event, therefore there are many different types of attributes some which are different depending on the event type. The other option we were thinking was do a field with a delimiter of key and values. So the field would be:

Name - Attributes:

Value - DocumentUrl:test.com;DocumentName:TestDocument

Thanks!

Kenny_Elkington
Kenny_ElkingtonAccepted solution
New Participant
January 29, 2016

I've seen similar things done just by using a text field, and then picking a delimiter and mapping each possible field to a particular array index.  So for example, you have these fields in your virtual object:

First Name

Last Name

Company

You would then serialize it with your selected delimiter like so:

Kenny|Elkington|Marketo

As long as you're serializing uniformly and always have the same indexes for fields, then you can get this:

#set($objectFieldArray = $myObjectList.get(0).split("|"))
#set($firstName = $objectFieldArray[0])

#set($lastName = $objectFieldArray[1])

#set($company = $objectFieldArray[2])

This will work for any type of flat record, but can be troublesome for objects with additional depth.