Populating one repeating table from another only shows first row - InfoPath Dev
in

InfoPath Dev

Populating one repeating table from another only shows first row

Last post 01-29-2009 11:01 AM by sarasdeva. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 10-27-2008 08:06 AM

    • RichW
    • Not Ranked
    • Joined on 10-27-2008
    • Posts 2

    Populating one repeating table from another only shows first row

    Hi,

    Please help, I'm stuck on this one!

    I have a repeating table that is receiving data from a secondary data source which is an MS Acess database query. The table reads the data correctly.

    I'm trying to load this data into a read-only second repeating table which is bound to my main XML data. I'm using rules applied to the secondary data source to set the value of the second repeating table. The problem is that only the first row is displayed.

    Any ideas out there?

    Thanks!

     

    -RichW 

     

     

  • 10-27-2008 10:45 PM In reply to

    Re: Populating one repeating table from another only shows first row

    Could you describe the rules you're using with a little more detail?  I think it may not be possible to use rules to copy the entire contents of a repeating section and that this may require code.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 10-28-2008 09:01 AM In reply to

    • RichW
    • Not Ranked
    • Joined on 10-27-2008
    • Posts 2

    Re: Populating one repeating table from another only shows first row

    The rules are applied to the data source that is populated from an MS Access query into repeating table 1. There are no conditions set and the action is:

         Set a field's value: Item_Description = @Item_Name

    where Item_Description is the from repeating table 2 and @Item is from repeating table 1

    You may be right about not being able to copy the entire contents from one repeating table to another. The rule *does* work but only for the first row.

    If this can't be done with repeating tables, are there any other controls that would do so? I'm trying to minimize coding if possible.

    Thanks for the reply.

     

     

  • 12-10-2008 10:57 AM In reply to

    Re: Populating one repeating table from another only shows first row

     I am also having a very similar issue. I have only a couple weeks experience with infopath 2003.  The form I'm creating is fairly difficult to describe, but let me give this a try (are you any good at word problems?). I have a repeating table that only contains one text box my:Defaults the table XCollection name is Defaults_22. I have a second repeating table outside of Defaults_22 with the XCollection name of Con_16. Inside Con_16 I have another repeating table with the XCollection name Pin_14. I want the values within Defaults_22 to set the values inside Pin_14.

    The reasoning is that Con_16 may have many rows and every row will need to have the default values of Defaults_22 already set for the (rows inside the rows) Pin_14. I will need to have the freedom to add or remove a row in Pin_14 for each unique row of Con_16. This data is being placed into an access database. Outside that of setting the defualts the form does work with the database, unfortunatly it get tedious to constantly add the default values to each row within Pin_14.

    I suscpect that some programming will be needed. I am an experienced embedded c programmer, but unfortunatly this skill doesn't seem to trasfer well when dealing with infopath forms outside that of logical process. 

    Any help would be appreceated, even a suggestion.

     Regards

  • 12-11-2008 02:14 PM In reply to

    Re: Populating one repeating table from another only shows first row

     I'm having a similar problem as well.  I've been using Infopath for about 10 hours with no programming experience.  I've managed to fumble through and get my bosses, spreadsheet into InfoPath using different views for each tab.  He has a table that is prepopulated with an autonumber field, he has a room descriptions field, he has a quantity field, a room size field and a function field that multiplies the room size by the number of rooms.  I can do this with a static table but he will never be able to add another row unless I fix the form.  I saw that InfoPath has repeating tables but I'm not sure how to prepopulate this table?  Anybody know how to do this? Also sorry for thread jacking.

    Murphy tha Dog
  • 12-11-2008 03:13 PM In reply to

    Re: Populating one repeating table from another only shows first row

     In my Access database I have several tables that has an autonumber, but in my form I just ignore them (ie. not displayed on the form) because it is generated when I submit the form. Are you wanting to add your existing fields to repeat table, or are you wanting your existing fields to have a pre-set value determined elsewhere in the form and repeat? If it is the first issue then simple make a repeat table from a data key (probably the autonumber field) and add all of the other fields inside that repeat table. If it is the latter, then we are having the same issue. It seems like something that should be easy and wouldn't need code to do.

    Let me describe my case in more details.

    I have Connector

    This connector has many cavities

    Each cavity can have several different terminal pins, but usually all cavities have at least some terminal pins in common

    So my structure is like so,

    -Connector

    -->Cavity

    ---> Terminals

    The "Cavity" is a repeat table that has the name of the pin and location and another repeating table that list all of the possible "Terminals" that can fit inside this cavity. (there are many more attributes in each table)

     I already have code that creates an X number of "Cavity" rows in the repeat table as determined by an attribute of the "Connector".

    I want to be able to have another Repeat table called "Defaults" and have that information copied to "Terminals"

    So I would like to have a structure like so where Defaults and Cavity are on the same level.

    -Connector

    -->Defaults

    -->Cavity

    ---> Terminals

     

    Any help would be much appreciated. 

     

  • 12-17-2008 07:54 AM In reply to

    Re: Populating one repeating table from another only shows first row

     After much work and on preview 980 (yes, that is 980 different previews learning this) I have create this code snippit that works for me very well.

    This is currently connected to a MS access database, but if I was to create an XML structure for this it would probably look like this

    <myFields>

          <dataFields>

              <RepeatTableA>

                   <RepeatTableDefault>

                        <myFieldElement>

                   </RepeatTableDefault>

                   <RepeatTableAB>

                        <RepeatTableABC>

                             <RepeatTableABCattribute>

                       </RepeatTableABC>

                   </RepeatTableAB>

              </RepeatTableA>

          </dataFields>

     </myFields>

     

    The field element myFieldElement is an  element that I made up in the form and is not part of the database.

    I have a OnAfterChange event being triggered for the myFieldElement with the following code. This will add a new row and copy the new data you just entered into the myFieldElement into the repeat table ABC. It will also change or delete any values in the repeat table ABC if you make a change to the repeat table RepeatTableDefault.  I added comments along the way

        if (eventObj.IsUndoRedo)
        {
                // An undo or redo operation has occurred and the DOM is read-only.
                return;
        }   
        if(eventObj.Operation == "Insert")
        {
            if(eventObj.Source.text)    //Check to see if the New data isn't blank, to prevent entering blank lines
            {
                //Grab onto the oNodeRepeatTableAB, this will be used to determin how many rows are in the AB Table
                var oNodeRepeatTableAB = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields/d:RepeatTableA/d:RepeatTableAB")

                for(var i = 1 ; i <= oNodeRepeatTableAB.length ; i++)
                {//Iterate thru each row of the AB table and add new row via a clone to each Repeat Table ABC
                   
                    //Select the RepeatTableABC to clone
                    var oNodeRepeatTableABC = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:RepeatTableA/d:RepeatTableAB[" + i + "]/d:RepeatTableABC")
                    oCloneNodeRepeatTableABC = oNodeRepeatTableABC.cloneNode(true)    //Create the clone
                       
                    //Set the attribute in the clone. The clone will be added as a new row to repeat table ABC
                    oCloneNodeRepeatTableABC.selectSingleNode("./@RepeatTableABCattribute").text = eventObj.Source.text
                   
                    //Grab the parent row (in this case the row of interest in Repeat Table AB) where the RepeatTableABC resides
                    var oNodeRepeatTableAB = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:RepeatTableA/d:RepeatTableAB[" + i + "]")

                    //Insert the new clone into the repeat table
                    oNodeRepeatTableAB.insertBefore(oCloneNodeRepeatTableABC, oNodeRepeatTableABC)
                }
            }
        }
        if(eventObj.Operation == "Delete")
        {
            if(eventObj.Source.text) //Check to see if there is any information to delete
            {
                //Grab onto the oNodeRepeatTableAB, this will be used to determin how many rows are in the repeat table AB
                var oNodeRepeatTableAB = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields/d:RepeatTableA/d:RepeatTableAB")

                for(var i = 1 ; i <= oNodeRepeatTableAB.length ; i++)
                {//Iterate thru each row of repeat table AB and remove the matching information
                   
                    //Select the rows within repeat table ABC that resides inside row(i) of repeat table AB that have the matching attribute of the desired text to be removed
                    var oNodeRepeatTableABC = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields/d:RepeatTableA/d:RepeatTableAB[" + i + "]/d:RepeatTableABC[@RepeatTableABCattribute='" + eventObj.Source.text + "']")
                   
                    //Remove all rows within Repeat Table ABC that have the desired text to be removed
                    oNodeRepeatTableABC.removeAll()
                }
            }
        }

     

    I have spent much time learning JS and the DOM structure in the last week. If there are practices that i'm doing in this code which are ill advise or not suggested please inform me.  I have compared the data in the Access database and the data is being submitted without issue. I would like to thank this forum for the support it has provided, without this forum and it's articals; I wouldn't have been able to finish this stage of my project. I hope this code helps with anybody wanting to copy the contents from table to another.

  • 12-17-2008 08:27 AM In reply to

    Re: Populating one repeating table from another only shows first row

    Thanks for sharing this.  It looks to me like your code is selecting groups of nodes and assigning the groups to a variable, and then not actually using the contents of the variable except to look at the number of items in the set.  I think the code would be just a bit more efficient as follows (note the bold parts that show what I've changed).

    MrQuestion:

        if (eventObj.IsUndoRedo)
        {
                // An undo or redo operation has occurred and the DOM is read-only.
                return;
        }   
        if(eventObj.Operation == "Insert")
        {
            if(eventObj.Source.text)    //Check to see if the New data isn't blank, to prevent entering blank lines
            {
                //Grab onto the oNodeRepeatTableAB, this will be used to determin how many rows are in the AB Table
                var oNodeRepeatTableAB = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields/d:RepeatTableA/d:RepeatTableAB")

                for(var i = 0 ; i < oNodeRepeatTableAB.length ; i++)
                {//Iterate thru each row of the AB table and add new row via a clone to each Repeat Table ABC
                   
                    //Select the RepeatTableABC to clone
                    var oNodeRepeatTableABC = oNodeRepeatTableAB[i].selectSingleNode("d:RepeatTableABC")
                    oCloneNodeRepeatTableABC = oNodeRepeatTableABC.cloneNode(true)    //Create the clone
                       
                    //Set the attribute in the clone. The clone will be added as a new row to repeat table ABC
                    oCloneNodeRepeatTableABC.selectSingleNode("./@RepeatTableABCattribute").text = eventObj.Source.text 

                    // line deleted here

                    //Insert the new clone into the repeat table
                    oNodeRepeatTableAB[i].insertBefore(oCloneNodeRepeatTableABC, oNodeRepeatTableABC)
                }
            }
        }
        if(eventObj.Operation == "Delete")
        {
            if(eventObj.Source.text) //Check to see if there is any information to delete
            {
                //Select all nodes that should be removed
                var oNodesToRemove = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields/d:RepeatTableA/d:RepeatTableAB/d:RepeatTableABC[@RepeatTableABCattribute='" + eventObj.Source.text + "']")

                oNodesToRemove.removeAll()
            }
        }

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 12-17-2008 09:41 AM In reply to

    Re: Populating one repeating table from another only shows first row

     Thank you,

     I followed your suggestions, and it works just as well. Plus it's easier to read. 

    Regards,

  • 01-29-2009 11:01 AM In reply to

    Re: Populating one repeating table from another only shows first row

    Is it possible to do the same with out using code...

    I am having a contact selector which stores data as a repeating group. I want to assign(replicate) the contents of the group to a repeating table. I should not use code for the same..

    -------------------------------------------
    Regards
    Saras...
Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.