Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

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

Avatar

Avatar
Level 1
JoshuelPattersonRM
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile

Avatar
Level 1
JoshuelPattersonRM
Level 1

Likes

0 likes

Total Posts

2 posts

Correct Reply

0 solutions
View profile
JoshuelPattersonRM
Level 1

29-03-2021

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 %>
<% } %>
<% } %>

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
MVP
Darren_Bowers
MVP

Likes

80 likes

Total Posts

277 posts

Correct Reply

87 solutions
Top badges earned
Validate 1
Affirm 50
Establish
Give Back 3
Applaud 25
View profile

Avatar
Validate 1
MVP
Darren_Bowers
MVP

Likes

80 likes

Total Posts

277 posts

Correct Reply

87 solutions
Top badges earned
Validate 1
Affirm 50
Establish
Give Back 3
Applaud 25
View profile
Darren_Bowers
MVP

30-03-2021

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

Answers (2)

Answers (2)

Avatar

Avatar
Establish
MVP
wodnicki
MVP

Likes

976 likes

Total Posts

1,096 posts

Correct Reply

514 solutions
Top badges earned
Establish
Affirm 500
Contributor
Shape 1
Give Back 100
View profile

Avatar
Establish
MVP
wodnicki
MVP

Likes

976 likes

Total Posts

1,096 posts

Correct Reply

514 solutions
Top badges earned
Establish
Affirm 500
Contributor
Shape 1
Give Back 100
View profile
wodnicki
MVP

01-04-2021

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

Avatar
Give Back 50
Employee
Sukrity_Wadhwa
Employee

Likes

154 likes

Total Posts

910 posts

Correct Reply

35 solutions
Top badges earned
Give Back 50
Validate 1000
Validate 500
Validate 250
Validate 100
View profile

Avatar
Give Back 50
Employee
Sukrity_Wadhwa
Employee

Likes

154 likes

Total Posts

910 posts

Correct Reply

35 solutions
Top badges earned
Give Back 50
Validate 1000
Validate 500
Validate 250
Validate 100
View profile
Sukrity_Wadhwa
Employee

13-04-2021

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!