11 Replies Latest reply on Sep 18, 2018 11:14 AM by Sanford Whiteman

    Can you script a table inside of a custom token?

    Alex Bridges

      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!

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

          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.

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

              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.

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

                  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

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

                      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?

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

                          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

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

                            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.

                            2 of 2 people found this helpful
                              • Re: Can you script a table inside of a custom token?
                                Alex Bridges

                                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!

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

                                Did you send email to a lead using the Email editor?

                                Or

                                Did you write a smart campaign to send the test email?

                                 

                                Try the second way and see if that works...

                                 

                                Rajesh