Expand my Community achievements bar.

Adobe Campaign User Groups are live now. Join our Adobe Campaign User Groups and connect with your local leaders!
SOLVED

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

Avatar

Level 1

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 %>
<% } %>
<% } %>
1 Accepted Solution

Avatar

Correct answer by
Level 9

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

View solution in original post

3 Replies

Avatar

Correct answer by
Level 9

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

Avatar

Community Advisor

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

Avatar

Administrator

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!



Sukrity Wadhwa