SOLVED

String index out of range: -1 for Custom Object Lookup

Go to solution
Stephen_Baker2
Level 2

String index out of range: -1 for Custom Object Lookup

Attached an image of all parts combined.

I have a test object with a currency property for a lead but attempting to grab it in a token is resulting in an index error.

* custom object field is of type currency

* it returns index error no matter what get() value is set to

* verified the property exists under the custom object for the lead used in preview

* removing { } from the object reference doesn't change the error (don't think this matters)

* this is a one-to-many relationship object that dedupes and links by Email Address

* expected outcome is token pulls in a single value from the custom object for the target person (custom object has one line item per email address)

Error:

Cannot get email content-

An error occurred when procesing the email Rendered_Email_Velocity_Error_Area_?!

String index out of range: -1 near

?

Code:

#set ( $render = $2018TaxSeason_cList.get(0).preApprovalAmount )

$render

Any insight greatly appreciated, am exhausted in efforts to figure out how custom objects work. Docs state it pulls in a list of up to 10 items by default, not sure in a one-to-many relationship if this means it pulls in 10 top leads or 10 top properties for each lead when the token runs.

1 ACCEPTED SOLUTION

Accepted Solutions
Stephen_Baker2
Level 2

Re: String index out of range: -1 for Custom Object Lookup

Heh. Noticed it was changing syntax highlighting when switching to another object.

Wasn't working with the year (number) in the object name. Excluding year in a new object fixed the issue.

Probably shouldn't let you save objects with integers but ¯\_(ツ)_/¯

markeko.png

$context["loweredCredit_cList"]

$context["loweredCredit_cList"].class

${loweredCredit_cList.get(0).emailAddress}

${loweredCredit_cList.get(0).minimumDown}

${loweredCredit_cList.get(0).preApprovedAmount}

View solution in original post

7 REPLIES 7
SanfordWhiteman
Level 10 - Community Moderator

Re: String index out of range: -1 for Custom Object Lookup

Something interesting here that I'll mention in a moment, if my suspicions are correct.

What output do you get from this token (making sure to check off the CO and the property in the tree):

$context["2018TaxSeason_cList"]

$context["2018TaxSeason_cList"].class

Stephen_Baker2
Level 2

Re: String index out of range: -1 for Custom Object Lookup

Oddly enough or to be expected: it returns the same error.

crappy_velocity_part_2_the_reckoning.png

SanfordWhiteman
Level 10 - Community Moderator

Re: String index out of range: -1 for Custom Object Lookup

Do you still have the original token, or any other Velocity token, in this email?

Stephen_Baker2
Level 2

Re: String index out of range: -1 for Custom Object Lookup

I had overwritten the original token. I made a brand new token and checked off the same CO property but same error.

I removed every other token and bit of content to eliminate the possibility of "oops that shouldn't be there".

<html xmlns="http://www.w3.org/1999/xhtml">

  <head>

  </head>

  <body>

    <table>

      <tbody>

        <tr>

          <td>{{my.atrocity}}</td>

        </tr>

      </tbody>

    </table>

  </body>

</html>

my.atrocity token:

$context["2018TaxSeason_cList"]

$context["2018TaxSeason_cList"].class

SanfordWhiteman
Level 10 - Community Moderator

Re: String index out of range: -1 for Custom Object Lookup

And does this same behavior exist with another CO, like Vehicle Inquiry?

Stephen_Baker2
Level 2

Re: String index out of range: -1 for Custom Object Lookup

Heh. Noticed it was changing syntax highlighting when switching to another object.

Wasn't working with the year (number) in the object name. Excluding year in a new object fixed the issue.

Probably shouldn't let you save objects with integers but ¯\_(ツ)_/¯

markeko.png

$context["loweredCredit_cList"]

$context["loweredCredit_cList"].class

${loweredCredit_cList.get(0).emailAddress}

${loweredCredit_cList.get(0).minimumDown}

${loweredCredit_cList.get(0).preApprovedAmount}

SanfordWhiteman
Level 10 - Community Moderator

Re: String index out of range: -1 for Custom Object Lookup

That was exactly what my suspicions were above!

Note the problem is specific to Marketo's Velocity config, not to Velocity in general.

Normally (when Velocity is used in Java-based websites, for example), while neither a Java variable nor a corresponding VTL reference ($something) can start with a number, you can still have a key within the Velocity $context reference that starts with a number. That is, if you access it as $99something, you will fail, but if you make sure to use bracketed-key syntax $context["99something"] all the time, it will work.  However, Marketo is doing some kind of pre- or post-processing that makes it not work here, even w/brackets.  And as you say, COs with numeroalphabetic names shouldn't be allowed because of this incompatibility.