SOLVED

Can you script a table inside of a custom token?

Go to solution
Alex_Bridges3
Level 2

Can you script a table inside of a custom token?

This thread started as a result of the outcome from this previous thread: How to get a token script to display information from Opportunity Object?

I am creating a template that includes several tables, which has tokens from the lead object, and needs tokens from the opportunity object. The number of tokens required exceeds 40 tokens - the limit in a given email.

My first workaround was to use formula fields, but discovered I can't use custom tokens created from the opportunity object in formula fields.

My next thought was to create a custom token with the content of the formula field - script a table and put all the needed fields within it. How would I go about having a velocity-scripted token recognize HTML, though? In our example case, let's say I want my one custom token to have the code for one table. The table has 10 rows and 4 columns. Half of my field values would be based on the lead object, while the other half are based on the opportunity object. How would I script to include the table with 20 tokens?

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Alex_Bridges3
Level 2

Re: Can you script a table inside of a custom token?

Marketo support gave me the official answer - I can't do it. Basically, if I'm attempting to display more than 60 "non-Marketo" fields (anything synced to an SFDC field; either on the opportunity object, or a custom SFDC field), it won't work. No workarounds. I brought up this thread and they said that if it's a standard Marketo field, it would work, but otherwise, there's no way. I'm not entirely sure I believe them, but they were pretty steadfast about it.

View solution in original post

13 REPLIES 13
SanfordWhiteman
Level 10 - Community Moderator

Re: Can you script a table inside of a custom token?

How would I go about having a velocity-scripted token recognize HTML, though? In our example case, let's say I have one table that has 10 rows and 4 columns. Half of my field values would be based on the lead object, while the other half are based on the opportunity object. The order of my field values isn't flexible, as our proof of concept was already approved in the order it's currently in.

Velocity doesn't need to "recognize" HTML, if you mean parsing HTML, in this case (VTL it does have HTML-escaping functions, though).

It sounds like you want to output an HTML <table> element and all of its child elements from Velocity, and it's perfectly suited for that.

Alex_Bridges3
Level 2

Re: Can you script a table inside of a custom token?

I scripted the tokens out, but I'm running into an issue where each table/token works fine on its own, but I seem to hit a limit where the Marketo previewer pukes. Is there a limit of some kind as far as the data it will display? I can get around 63 out of 94 field values to display, or 6 of my 9 tables put in before the previewer suddenly "can't connect." I tested each table one by one, and tried different combinations; each table individually works, and it breaks no matter which combination I use if I go beyond a certain number of field values. I even tried just making one "master token" with all the tables, but it broke too.

Rajesh_Talele13
Level 1

Re: Can you script a table inside of a custom token?

Hi Alex,

Did you only try in the 'preview' or did you actually send this email to yourself or a test contact. May be the renderer for the 'preview' functionality is 'limited' while actual email rendering while sending will work fine.

How about sending this email to a test lead and see if all the values are rendered.

Hope this helps..

Rajesh Talele

Alex_Bridges3
Level 2

Re: Can you script a table inside of a custom token?

You can't. I tried sending the email to a lead, and although Marketo will allow me to approve it, the send fails. It doesn't even give an error message, which I saw before, when I initially was trying to create the template. That's how I found out Marketo won't send an email with over 40 tokens; it appears there's some kind of limit on the amount of fields it will pull in, period.

Am I just out of luck, here?

Rajesh_Talele13
Level 1

Re: Can you script a table inside of a custom token?

Hmm. I guess so..

Did you reach out to support? Not sure if it is some 'configuration' they can change for your server to allow more tokens in an email.

Or

if it is baked in the core code and not configurable. In that case, we are out of luck..

Rajesh Talele

SanfordWhiteman
Level 10 - Community Moderator

Re: Can you script a table inside of a custom token?

it appears there's some kind of limit on the amount of fields it will pull in, period.

I would be looking at what you're doing with the fields, not the number of fields.  I have tokens with 200 lead fields, doing extreme things like an encryption routine in JavaScript running inside Velocity, and they don't have such a problem.

But Velocity does have a stack depth limit: if you have a lot of nested loops you might exceed that. (Or of course if you have an infinite loop by accident, eventually you'll hit a timeout.)

Need to know more about how you're assembling the HTML with these fields.  20 fields from the Lead, 20 fields from the (latest?) Opportunity doesn't signal any problems.

Alex_Bridges3
Level 2

Re: Can you script a table inside of a custom token?

Here's a sample of what one of the token scripts looks like:

<table>

<tr>

<td>Label:</td>

<td>$display.alt($lead.Field1, "---") $display.alt($lead.Field2, "---")</td>

<td> </td>

</tr>

<tr>

<td >Label:</td>

<td>$display.alt($lead.Field3, "---")</td>

<td>$display.alt($lead.Field4, "---")</td>

</tr>

<tr>

<td> </td>

<td>$display.alt($OpportunityList[0].Field5, "---") </td>

<td>$display.alt($OpportunityList[0].Field6, "---")</td>

</tr>

<tr>

<td>Label:</td>

<td>$display.alt($OpportunityList.get(0).Field7, "---")</td>

<td> </td>

</tr>

</table>

Due to company security policy, I'm very limited in what I'm able to share, so that's why it looks so basic. But that's the gist of what's inside the token script, save for inline styling and actual field names. The largest one of these tokens contains a table with 6 cells per row, and 18 field values, all pulled from the oppty object. The above script is the only one that pulls anything off the lead object.

Initially I had the tokens scripted to start with #set and end with #end, which worked if I had only one token, but that broke if I added more than one token in the editor. The plain script seems to work fine, up to a point, as long as I don't exceed a certain amount. I tried putting all the tables in a "master" token, and it broke the same way, with or without the #set and #end.

I have clearance to put a simplified version of the entire thing up (all the tables!), but I wasn't sure if that would be overkill. I figured I'd start with this and post the whole thing if you wanted to see that, too.

Thanks!

SanfordWhiteman
Level 10 - Community Moderator

Re: Can you script a table inside of a custom token?

This really is very simple stuff.  I was able to test with 18 CO field values, no problem (like i said, I have 200 fields ref'd in some of my tokens).

Initially I had the tokens scripted to start with #set and end with #end, which worked if I had only one token

I don't know what you mean here. Velocity doesn't have to start with #set or end with #end. #set is only to create a reference (i.e. variable) and #end only to close a #foreach loop or #if condition. An #end without any starting statement is definitely going to be a problem.

You can send me the whole master token via email, I know you have it.

Alex_Bridges3
Level 2

Re: Can you script a table inside of a custom token?

I actually don't have your email anymore, as I switched jobs since the last time I used it.   How can I get in touch? The security stuff where I am now is crazy strict, like I can't send attachments to personal email or I get fired level of strict. However, I can dumb-down the master token and put that in here; it'll give me a chance to debug. (I can also ask my manager what our options are, as this project is a high priority for us.)