InfoPath 2010 - Adding new rows to Repeating Table using C# - InfoPath Dev
in

InfoPath Dev

Qdabra® Training

Use our Google Custom Search for best site search results.

InfoPath 2010 - Adding new rows to Repeating Table using C#

Last post 02-16-2012 10:39 AM by Hilary Stoupa. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-15-2012 07:00 AM

    InfoPath 2010 - Adding new rows to Repeating Table using C#

    Yeah, this is an age-old topic.  Sorry to bore everyone. :(

    But in InfoPath 2010 most of the suggestions I've read about in your forums don't seem to work.  Here's a snippet of my code that I use today to populate a Repeating Table with values.  It works, but if anyone can quickly spot a more efficient way of doing this by all means let me know!


                   DataSource sapDupes = this.DataSources["ZOLP_CHECK_DUPLICATE_ADDRESS"];
                   XPathNavigator sapReturn = sapDupes.CreateNavigator().SelectSingleNode("//dfs:dataFields/tns:ZOLP_CHECK_DUPLICATE_ADDRESSResponse", NamespaceManager);

                    if (sapReturn.SelectSingleNode("RETURN_COUNT", NamespaceManager).InnerXml != "0")
                    {
                        // Set Secondary (originating) Data Source, line item and repeating group (item)
                        XPathNavigator sapLineItem = sapDupes.CreateNavigator().SelectSingleNode("//dfs:dataFields/tns:ZOLP_CHECK_DUPLICATE_ADDRESSResponse/OPEN_NOTIFS_T", NamespaceManager);
                        XPathNodeIterator sapCodes = sapLineItem.Select("item", NamespaceManager);

                        // Set internal (destination) repeating group (DUPLICATE_ITEMS)
                        XPathNavigator onlineLineItem = MainDataSource.CreateNavigator().SelectSingleNode("//my:Duplicates", NamespaceManager);
                        XPathNodeIterator onlineCodes = onlineLineItem.Select("./my:Duplicate_Items", NamespaceManager);

                        for (int i = 1; i < sapCodes.Count; i++)
                        {
                           

                            // blank out the first line & fields in the repeating table
                            onlineLineItem.AppendChildElement("my", "Duplicate_Items", onlineLineItem.LookupNamespace(onlineLineItem.Prefix), "");
                            XPathNavigator onlineItem = onlineLineItem.SelectSingleNode("*[last()]", NamespaceManager);
                            onlineItem.AppendChildElement("my", "Dupes_Date", onlineItem.LookupNamespace(onlineItem.Prefix), "");
                            onlineItem.AppendChildElement("my", "Dupes_Notification", onlineItem.LookupNamespace(onlineItem.Prefix), "");
                            onlineItem.AppendChildElement("my", "Dupes_Account", onlineItem.LookupNamespace(onlineItem.Prefix), "");
                          
                            // set the position on both the originating (sap) position and the InfoPath position
                            XPathNavigator sapCode = sapLineItem.CreateNavigator().SelectSingleNode("item[position() = " + i + "]", NamespaceManager);

                            onlineItem.SelectSingleNode("my:Dupes_Date", NamespaceManager).SetValue(sapCode.SelectSingleNode("ERDAT", NamespaceManager).InnerXml);

                            onlineItem.SelectSingleNode("my:Dupes_Notification", NamespaceManager).SetValue(sapCode.SelectSingleNode("QMNUM", NamespaceManager).InnerXml);
                            onlineItem.SelectSingleNode("my:Dupes_Account", NamespaceManager).SetValue(sapCode.SelectSingleNode("NAME1", NamespaceManager).InnerXml);
                          

                        }

                    } 

    Chris ... er, Arthur Fonzarelli!
  • 02-15-2012 11:06 AM In reply to

    Re: InfoPath 2010 - Adding new rows to Repeating Table using C#

    An alternative you can look into is to use qRules which easily allows you to insert new rows to a repeating table without code.  More info: http://www.qdabra.com/en/products/qRules_top.aspx

    Anson Hidajat
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 02-15-2012 11:46 AM In reply to

    Re: InfoPath 2010 - Adding new rows to Repeating Table using C#

    Anson, Question about that - can I do EXACTLY what I'm doing in my code without any code using qRules? What command would I use?
    Chris ... er, Arthur Fonzarelli!
  • 02-16-2012 10:29 AM In reply to

    Re: InfoPath 2010 - Adding new rows to Repeating Table using C#

    Well you can certainly delete and insert nodes in a repeating table.  If you are interested in learning more, you can download a free trial and see if it offers all the functionality you need: http://www.qdabra.com/en/products/download/qRulesTrial.aspx

    Anson Hidajat
    Qdabra® Software/ InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

  • 02-16-2012 10:39 AM In reply to

    Re: InfoPath 2010 - Adding new rows to Repeating Table using C#

    Just to add to this - You could use the Delete command to delete existing rows. Then if your source and destination data sources match, you can use CopyTable to copy repeating data from one to the other. If they don't match, you can use the Insert command, a counter field and some XPath magic. I just did a demo video on this - check it out here. There's a sample form here, injected w/ a qRules trial that shouldn't expire till March 15, 2012, so you can check it out as well. It uses XML data sources, so should run just fine in any enviro.

    Hilary Stoupa

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