Store objects in custom fields | Community
Skip to main content
New Participant
November 22, 2022
Solved

Store objects in custom fields

  • November 22, 2022
  • 1 reply
  • 3229 views

Hi there, 

 

We are using different online calculator which post their data as for post. In this form post all data are seperate data field. 

The disadvantage is that all this filed will be overwritten in case of the next form post. 

 

We like to store this data as object within one custom field. From what I read the best way would be to use a custom text area field. As custom ojects data can't be stored via smart campaign flows we like to use a custom field. 

 

There are several posts on this topic but none of them worked for me.

From what I found out there are ways like the following:

https://nation.marketo.com/t5/product-discussions/tokenising-json-field-in-marketo/td-p/27919 

Info from @sanfordwhiteman 


You store data as JSON 

{ "id" : 123, "booking_id" : "ABC","tax" : 1.875 }

 

You transform this data using "set" and "evalutate"

#set( $jsonProduct = '#set( $jsonProduct = ' + $Bookings2_cList[0].jsonProduct + ' )' ) #evaluate( $jsonProduct )

 

After this that data should be transformed into an velocity map. 

{id=123, booking_id=ABC, tax=1.875}

 

I tried to get the data using a request like $object.id. But in my cas it didn't work. 



Do you know what I do wrong?
How shoud I store data in my marketo custom data fields? (not in a custom object)

How can I add this data to an emaily velocity script? 

How can I access a specific information via Key?

What do I have to consider for the values (does and don'ts)?

Thanks a lot. 

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 SanfordWhiteman

You store data as JSON { "id" : 123, "booking_id" : "ABC","tax" : 1.875 }

 

You transform this data using "set" and "evalutate"

#set( $jsonProduct = '#set( $jsonProduct = ' + $Bookings2_cList[0].jsonProduct + ' )' ) #evaluate( $jsonProduct )

The pattern is:

#set( $hydrate = "${esc.h}set( ${esc.d}hydratedObject = " + $jsonString + " )" ) #evaluate( $hydrate )

 

Then $hydratedObject is an ArrayList or LinkedHashMap with nested properties. All the usual Java (6) methods are usable.

 

The important guidelines for the JSON are:

  • you can’t use null (it’s not a meaningful keyword in VTL)
  • you must use long Unicode escapes like \u000A, not short “macro escapes” like \n

 

 

1 reply

SanfordWhiteman
SanfordWhitemanAccepted solution
New Participant
November 22, 2022

You store data as JSON { "id" : 123, "booking_id" : "ABC","tax" : 1.875 }

 

You transform this data using "set" and "evalutate"

#set( $jsonProduct = '#set( $jsonProduct = ' + $Bookings2_cList[0].jsonProduct + ' )' ) #evaluate( $jsonProduct )

The pattern is:

#set( $hydrate = "${esc.h}set( ${esc.d}hydratedObject = " + $jsonString + " )" ) #evaluate( $hydrate )

 

Then $hydratedObject is an ArrayList or LinkedHashMap with nested properties. All the usual Java (6) methods are usable.

 

The important guidelines for the JSON are:

  • you can’t use null (it’s not a meaningful keyword in VTL)
  • you must use long Unicode escapes like \u000A, not short “macro escapes” like \n

 

 

New Participant
November 23, 2022

Hi @sanfordwhiteman
thank you. Unfortunatley it did not work for me. I tried it the following:


Creat a custom field of type text area.  

 

That field could be requested in velocity using the following token

 

$lead.mktoTestTextArea

 

 

I try to use your code while the $jsonString is exchanged against my custom field token. 

 

#set( $hydrate = "${esc.h}set( ${esc.d}hydratedObject = " + $lead.mktoTestTextArea + " )" ) #evaluate( $hydrate )

 


If I try to use this email script token in my mail I get the following error message:
annot get email content- 

 

<div>An error occurred when procesing the email Body! </div> <p>Encountered ")" near</p> <div><pre ></pre></div>

 

 

 

What am I doing wrong?