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

Array of repeatable fields in dynamic table

Avatar

Avatar
Give Back
Level 2
peartreeco
Level 2

Likes

5 likes

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Give Back
Ignite 1
Validate 1
Boost 5
Boost 3
View profile

Avatar
Give Back
Level 2
peartreeco
Level 2

Likes

5 likes

Total Posts

17 posts

Correct Reply

1 solution
Top badges earned
Give Back
Ignite 1
Validate 1
Boost 5
Boost 3
View profile
peartreeco
Level 2

17-07-2020

Hi, my form structure is:

Capture.JPG

I have a table (MonitorProductList) that has repeatable rows. Each row has  Product Name in Column A, Description in Column B and Price in Column C. 

I want to be able to take all of items in Column A and populate a dropdown on another repeatable subform on Page 2. The selection from this dropdown would then populate a Description and Price fields on Page 2  depending on row selection from the table. Can this be done with the code below? I tried it but the dropdown just shows 2 blank options.


// Get the values from the data model.
var monName = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].MProduct");
var monDesc = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].MDesc");
var monPrice = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].BPrice");

var mDD = new Array(" ",monName);
var mDis = new Array(null,monDesc);
var mPri = new Array (null,monPrice);

// Populate the part number Drop-down List.

function populatePartNo(dropdownField)
{
var i;
for (i=0; i < mDD.length; i++)
dropdownField.addItem(mDD[i]);
}

// Populate the description and unit price fields.

function getDesc(partNumber, descField, itemPrice)
{
var i;
for (i = 0; i < mDD.length; i++) // Go through the entire list of part numbers to find the one that is currently selected.
{
if (mDD[i] == partNumber) // When we find the part number currently selected.
{
descField.rawValue = mDis[i]; // Put the description in the description field
itemPrice.rawValue = mPri[i]; // and put the unit price in the unit price field.
break; // No need to go further if there is a match.
}
}
}

 

Thank you 

Accepted Solutions (0)

Answers (2)

Answers (2)

Avatar

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile

Avatar
Springboard
MVP
Magus069
MVP

Likes

143 likes

Total Posts

1,078 posts

Correct Reply

155 solutions
Top badges earned
Springboard
Validate 1
Ignite 3
Ignite 1
Establish
View profile
Magus069
MVP

22-07-2020

Hi there,

 

By the look of your variable statements, I think you're trying to change the inital array value that resolveNodes() has returned,

Which is why you are ending up with only 2 length array.

 

 

//This section extract an array of items to retrieve a value directly to the designated object
var monName = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].MProduct");
var monDesc = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].MDesc");
var monPrice = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].BPrice");

//This here creates a new array of values, so technically index 0 is " " and index 1 is an array which contains the values you want to access...
var mDD = new Array(" ",monName);
var mDis = new Array(null,monDesc);
var mPri = new Array (null,monPrice);

 

 

The right way to extract a value from the array that resolveNodes got for you is the following:

 

//Instead of creating an array, resolveNodes returns a nodeList, and this class does not have an iterator function like an array
var monName = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].MProduct");
var monDesc = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].MDesc");
var monPrice = xfa.resolveNodes("ProductData.MonitorProductList.Row1[*].BPrice");

var mDD = new Array();

//Therefore, you will have to iterate through the list of items this way
for (var i = 0; i < monName.length; i++){
     //".rawValue" is assuming you want to extract only the values of the fields
     mDD.push(monName.item(i).rawValue);
}

 

Maybe this can help you understand and/or if you want to achieve it another way, but you can understand that resolveNodes does not return an Array object.

http://adobelivecycledesignercookbookbybr001.blogspot.com/2014/07/yet-another-way-of-looping-though-...

 

Also take note that duplicates will appear in the drop down list if not handled.

 

I hope this will help.

Avatar

Avatar
Affirm 100
Employee
Kosta_Prokopiu1
Employee

Likes

165 likes

Total Posts

369 posts

Correct Reply

107 solutions
Top badges earned
Affirm 100
Validate 1
Establish
Give Back 5
Give Back 3
View profile

Avatar
Affirm 100
Employee
Kosta_Prokopiu1
Employee

Likes

165 likes

Total Posts

369 posts

Correct Reply

107 solutions
Top badges earned
Affirm 100
Validate 1
Establish
Give Back 5
Give Back 3
View profile
Kosta_Prokopiu1
Employee

20-07-2020

quick comment as I have no time to recreate your setup here. The resolveNodes extracts complete nodes, not values. The addItem needs to add a text not an object.
I am also not sure if you address the fields correctly. You call it data model but to me it looks more like the object model.
This is important because if you address the fields you must use .rawValue to get the text, if you really access data from the data model then it would be .values

Try (assuming that the previous logic actually worked):

for (i=0; i < mDD.length; i++)
dropdownField.addItem(mDD[i].value (or .rawValue) );