Hi Adam and thanks for your reply. To be a bit more specific about the layout of the form...here is the best way I can present it.
<Repeating Section>
<Master>
</Master>
<Detail>
<Repeat Table1>
<Repeat Table2>
</Repeat Table2>
<Repeat Table 3>
</Repeat Table3>
</Repeat Table1>
</Detail>
</Repeating Section>
The repeating sections aren't really important for this problem since the data in each repeating section is completely independant of each other. The purpose of the master/detail sections is to give the users some versioning ability to the form. The master table is basically just the date, version # and status and the detail section has all the relevant data needed. The issue is that when a new version is created most of the data is the same from the previous version with maybe 1 or 2 modifications. To simplify the process for the user I wanted to copy over the previous versions data to the new version. This was fine for the individual fields inside the detail section that were not part of the repeating table.
With code I am trying to count the number of times a table has repeated, create a loop based on the number of records and then copy them from the preceding detail section to the current. Since the original posting I found some code online that is suppose to do what I want but it never enters the loops. The code with modifications to fit my example is below.
The full Xpath for the Colorways_Table is: /my:myFields/my:Domestic_Tab/my:Domestic_Logo/my:Domestic_Logo_Record/my:Domestic_Embroidery_Version/my:Colorways/my:Colorways_Table
The Xpath for the Detail section is the same up and including my:Domestic_Embroidery_Version.
var objTable1 = XDocument.DOM.selectNodes("preceding-sibling::*[1]/my:Colorways/my:Colorways_Table")
var objXMLNodes;
for(var i = 0;i <= objTable1.length - 1;i++)
{
var objTable2 = XDocument.DOM.selectSingleNode("//my:Colorways/my:Colorways_Table[last()]")
if(objTable2.selectSingleNode("my:Colorway_Test").text != "")
{
XDocument.View.ExecuteAction("xCollection::insert", "Colorways_Table_2");
}
var objTable2 = XDocument.DOM.selectSingleNode("//my:Colorways/my:Colorways_Table[last()]")
var objT1CurrentRow = objTable1.item(i);
objTable2.selectSingleNode("my:Colorway_Test").text = objT1CurrentRow.selectSingleNode("my:Colorway_Test").text
//objTable2.selectSingleNode("my:field4").text = objT1CurrentRow.selectSingleNode("my:field2").text
}
As I mentioned, no matter how many records I insert it will never go into the loop because objTable1.length keeps returning 0. I know it is very possible I am overlooking something simple as I am quite new to this. If you have any thoughts or advice please let me know. Thanks.
Chris