Copying Data to Repeating Table in Detail Section - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Copying Data to Repeating Table in Detail Section

Last post 10-08-2007 06:22 AM by adamrharding. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 09-27-2007 07:37 AM

    • feesh
    • Not Ranked
    • Joined on 09-25-2007
    • Posts 11

    Copying Data to Repeating Table in Detail Section

    Hi Everyone. I am fairly new to infopath but I have managed to teach myself what I think is most of the basics of the program. I have a reached a more complex problem that I need some help with.

    The base of the form consists of a Master and Detail section. Inside the detail section there are a couple of fields and then a Repeating Table that contains 2 more repeating tables inside. I would like all the data from the current detail section to be copied to the new detail section everytime a new master record is inserted. I accomplished this by putting a rule on the insert to copy over the data in the fields using the preceding-sibling function but I am stuck when it comes to the repeating table. Any help would be appreciated.

    I apologize if I wasn't clear. Let me know if more information is needed.

    Thanks.

    Chris

  • 10-05-2007 12:05 AM In reply to

    Re: Copying Data to Repeating Table in Detail Section

    Hi feesh

    What I think you have in group terms is

    Master

    Detail

    Repeat

    Repeat1  Repeat 2

    With this structure you say you can successfully copy across the detail section but not the repeating tables.  I would presume this is because they are preceding-preceding sibling or indeed preceding-preceding-preceding sibling.  I also presume that the first repeating table containing the other two repeating tables do not form part of the detail table as I would presume that they would otherwise copy accross in the preceding sibling.

    Anything else I can help with feel free to ask

    Adam

    Adam Harding
    Wales
    UK
  • 10-05-2007 11:53 AM In reply to

    • feesh
    • Not Ranked
    • Joined on 09-25-2007
    • Posts 11

    Re: Copying Data to Repeating Table in Detail Section

    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

     

     

     

  • 10-08-2007 06:22 AM In reply to

    Re: Copying Data to Repeating Table in Detail Section

    Chris

    I think you could do this without code by putting a button on the form defined as rules and custom code that creates a new form but also prepopulates the fields you want so button opens new form and in the form options, save and save as, Rules, and add a rule such that if a new form is opened up set Field A to (last Field A) and so on

    I hope this makes sense as I don't generally code unless there is no other way around.

    Cheers Adam

    Adam Harding
    Wales
    UK
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.