Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

Array of repeatable fields in dynamic table

Avatar

Level 2

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 

2 Replies

Avatar

Employee

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) );

 

Avatar

Level 10

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.