Skip to main content
Mar 29, 2021 8:51 PM UTC
Solved

ACC not recognizing bracket notation javascript, always returns "undefined"

I'm attempting to craft a property accessor for referencing a set of mapped fields in our targetData, within our template, however ACC is not honoring our usage of the bracket notation, regardless of whether or not we surround the property/field name with double quotes.

Is this a known bug with a workaround or a patch?


<%
var td = {
    passholderName_1: 'passholderName_1',
    passholderName_2: 'passholderName_2'
}
%>

<%
var conditional = "passholderName";
for (var a = 1; a < 12; a++) {
    var value = td[conditional + "_" + a];
    if (value) {
%>
<%= value %>
<% } %>
<% } %>
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Darren_Bowers
Darren_BowersAccepted solution
Level 9
Mar 31, 2021 12:02 AM UTC

Hi @joshuelpattersonrm - I tested your code and it works fine in a delivery template.

You should probably change the for loop limit to 3 as you only have 2 array items, but otherwise it works fine.

Cheers

Darren

3 replies

Darren_Bowers
Darren_BowersAccepted solution
Level 9
Mar 31, 2021 12:02 AM UTC

Hi @joshuelpattersonrm - I tested your code and it works fine in a delivery template.

You should probably change the for loop limit to 3 as you only have 2 array items, but otherwise it works fine.

Cheers

Darren

Translate
Jonathon_wodnicki
Community Advisor
Community Advisor
Apr 1, 2021 7:56 PM UTC

Hi,

 

Use this:

<% var td = { passholderName_1: 'passholderName_1', passholderName_2: 'passholderName_2', } Object .keys(td) .filter(function(k){return td[k]}) .forEach(function (k) {%><%= td[k] %><% }); %>

 

Thanks,

-Jon

Translate
Sukrity_Wadhwa
Level 4
Apr 13, 2021 8:45 AM UTC

Hi @joshuelpattersonrm,

Were any of the given solutions helpful to resolve your query or do you still need more help here? Do let us know.

Thanks!

Translate
Sukrity Wadhwa