Adding rows to Repeating Table - InfoPath Dev
in

InfoPath Dev

Adding rows to Repeating Table

Last post 04-03-2007 05:59 AM by BhailDa. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 03-21-2007 09:48 AM

    Adding rows to Repeating Table

    I'm trying to add rows to a repeating table through managed code. Everything work fine except that last data row that is read is repeated at the top of my repeating table. Here is the code in question:

    DataSource ds = this.DataSources[0];

    XPathNavigator servers = ds.CreateNavigator().SelectSingleNode("/my:myFields/my:Servers/my:group13/my:group14", this.NamespaceManager);

    servers = servers.Clone();

    XPathNavigator ServersNAV = ds3.CreateNavigator();

    XPathNodeIterator Serversiter = ServersNAV.Select("/dfs:myFields/dfs:dataFields/dfs:Server_List/@Server", this.NamespaceManager);

    while (Serversiter.MoveNext())
    {
    XPathNavigator servername = Serversiter.Current.Clone();

    servers.SelectSingleNode("my:field132", this.NamespaceManager).SetValue(servername.Value.ToString());

    XPathNavigator parent = ds.CreateNavigator().SelectSingleNode("/my:myFields/my:Servers/my:group13", this.NamespaceManager);
    parent.AppendChild(servers);
    }


    Here is the result:

    Name3
    Name1
    Name2
    Name3

    Notice that the last row (Name3) is being replicated at the top of the repeating table everytime. Haven't found anyone with an answer to this one.


  • 03-21-2007 11:49 AM In reply to

    Re: Adding rows to Repeating Table

    Hi Robert and welcome to our forums!

    It's cool that you're using managed code in IP2007 - I must confess that I have not done much of this myself. I didn't test this, but I think I see your problem. You're only cloning the 'servers' variable once. So in the loop only the very first 'parent.AppendChild(servers)' will change the DOM. Each subsequent call will move that node to the bottom of the children of that parent. I'm pretty sure you will want to execute 'servers = servers.Clone()' for each iteration of the loop.

    I'm not 100% sure that this is the problem, but that's what my intuition tells me, so let me know if it works!
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 03-21-2007 02:17 PM In reply to

    Re: Adding rows to Repeating Table

    Thanks for the reply. But that didn't work either. I walked through code and it's working like this.

    while (Serversiter.MoveNext()) Reads the iterator
    {

    servers = servers.Clone();

    XPathNavigator servername = Serversiter.Current.Clone(); Sets the XpathNavigator to the current Node

    servers.SelectSingleNode("my:field132", this.NamespaceManager).SetValue(servername.Value.ToString()); Set the value to the current node

    XPathNavigator parent = ds.CreateNavigator().SelectSingleNode("/my:myFields/my:Servers", this.NamespaceManager);

    Now by the time I get here the node has already been added to the parent. But I have No Idea where this is happening! So when it hits the Append below it adds it again.

    parent.AppendChild(servers);

    }


    Parent before the loop:



    <my:group14 xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-28T16:42:46">
    <my:field131></my:field131>
    <my:field132></my:field132>
    <my:field133>false</my:field133>
    </my:group14>


    Parent on the Append:


    <my:group14 xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-28T16:42:46">
    <my:field131></my:field131>
    <my:field132>D1COL500</my:field132>
    <my:field133>false</my:field133>
    </my:group14>
    <my:group14 xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-11-28T16:42:46">
    <my:field131/>
    <my:field132>D1COL500</my:field132>
    <my:field133>false</my:field133>
    </my:group14>
  • 03-21-2007 03:55 PM In reply to

    Re: Adding rows to Repeating Table

    Weird. I haven't played around with the IP2007 OM enough to know what's going wrong, but why are you doing this:

    XPathNavigator servername = Serversiter.Current.Clone(); 

    servers.SelectSingleNode("my:field132", this.NamespaceManager).SetValue(servername.Value.ToString());


    Couldn't it just be this:

    servers.SelectSingleNode("my:field132", this.NamespaceManager).SetValue(Serversiter.Current.Value.ToString());


    Maybe cloning behaves differently with the new OM, but I have a hunch that that is why you are seeing a problem. Maybe cloning a node automatically appends it to the "donor node's" parent.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 03-22-2007 11:27 AM In reply to

    Re: Adding rows to Repeating Table

    Changed the code to the following. Still the same problem. Anyone else out there have any ideas?


    XPathNodeIterator Serversiter = ServersNAV.Select("/dfs:myFields/dfs:dataFields/dfs:Server_List/@Server", this.NamespaceManager);

    XPathNavigator parent = ds.CreateNavigator().SelectSingleNode("/my:myFields/my:Servers", this.NamespaceManager);

    while (Serversiter.MoveNext())
    {

    servers.SelectSingleNode("my:field132", this.NamespaceManager).SetValue(Serversiter.Current.Value.ToString());

    parent.AppendChild(servers);

    }
  • 04-03-2007 05:57 AM In reply to

    • BhailDa
    • Not Ranked
    • Joined on 10-06-2006
    • United Kingdom
    • Posts 13

    Re: Adding rows to Repeating Table

    I have a similar issue. In my scenerio I have a Purchase Order with a table for Items. I may decide top populate the entire table my pressing button which in turn uses a web service lookup. the problem being that the table doesn't exist in mamanged code until populated by the user. Therefore need to reference the inner XML from the manifest and apply this as child. Its so flacky !! I have to say I hate XPathNavigator. I'd rather pass it back to a class gerered off the schema (.xsd) and add/change nodes there. Haven't worked out how to pass values back and forth like that yet. I'm a SAP Developer not InfoPath.

    Code Extract:

    XPathNavigator xn = MainDataSource.CreateNavigator();
    XPathNavigator xGroup = xn.SelectSingleNode("/my:myFields/my:group1", this.NamespaceManager);

    XPathNavigator xnNode = this.Template.Manifest.SelectSingleNode("//xsf:xDocumentClass/xsf:views/xsf:view[@name='MgTest']/xsf:editing/xsf:xmlToEdit[@name='group1_3']/xsf:editWith/xsf:fragmentToInsert/xsf:chooseFragment/my:group1", this.NamespaceManager);
    //Append the node from the Manifest file to the main DOM
    XPathNavigator xNode = xGroup.SelectSingleNode("/my:myFields/my:group1", this.NamespaceManager);
    DeleteNil(xNode);
    xNode.AppendChild(xnNode.InnerXml);
  • 04-03-2007 05:59 AM In reply to

    • BhailDa
    • Not Ranked
    • Joined on 10-06-2006
    • United Kingdom
    • Posts 13

    Re: Adding rows to Repeating Table

    The answer to your particular problem as it doesn't seem to be dealing with empty tables can be found at:

    http://blogs.msdn.com/infopath/archive/2006/12/15/another-way-of-sorting-repeating-data.aspx
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.