Copying data from secondary data source to repeating table (for Infopath 2010 browser form) - InfoPath Dev
in

InfoPath Dev

Copying data from secondary data source to repeating table (for Infopath 2010 browser form)

Last post 02-24-2013 12:19 PM by Patrick Halstead. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-24-2013 01:10 AM

    Copying data from secondary data source to repeating table (for Infopath 2010 browser form)

    Hi,

    I recently realized in almost the end of my creation process that the browser form do not support copy paste functionality from Excel. To set the scene - I am not able to implement Qdabra software,so the only way is to find a existing suitable solution on and was looking for some hints and tips on the web. Unfortunately I am not (yet) that brilliant with proposed solutions:

    1. I tried figuring out and understanding the solution proposed by Patrick here:

    http://www.infopathdev.com/blogs/patrick/archive/2011/09/03/free-sample-copying-repeating-data.aspx

     but I am confused by the fact that the "delete" and "put new 5 rows" buttosn relate to Qdabra secondary data source. I was trying to replicate the approach and building an example file myself, but somehow it did not work. Has somebody tried to implement the approach?

    Secondly I tried to find a code solution, and this time it brought a following results:

    I am able to copy over the content from secondary data source, number of rows match (have 3 rows in secondary xml file), but in my case only the first one is copied over and in my case 3 times.

    I also dont know if besided putting the code behnid the button - should i also put conditional action, which would refresh the connection to secondary data source upon button click?

    Plus the code I have used in VBA:

    Public Sub CTRL5_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
                ' Write your code here.

                Dim secDSNav As XPathNavigator = DataSources("MyContacts").CreateNavigator()

                ' Retrieve the rows of the secondary data source
                Dim rows As XPathNodeIterator = secDSNav.Select( _
                "/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW", _
                NamespaceManager)

                ' Loop through the rows of the secondary data source and fill the repeating table
                While rows.MoveNext()
                    Dim lastname As String = rows.Current.SelectSingleNode( _
                    "/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Title", NamespaceManager).Value
                    Dim firstname As String = rows.Current.SelectSingleNode( _
                    "/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:FirstName", NamespaceManager).Value
                    Dim email As String = rows.Current.SelectSingleNode( _
                    "/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Email", NamespaceManager).Value

                    ' Add the item to the repeating table
                    AddItem(lastname, firstname, email)
                End While

                DeleteFirstEmptyItem()


            End Sub


            Private Sub AddItem( _
            ByVal lastname As String, ByVal firstname As String, ByVal email As String)

                Dim doc As XmlDocument = New XmlDocument()
                Dim group As XmlNode = doc.CreateElement("group2", _
                NamespaceManager.LookupNamespace("my"))

                Dim field As XmlNode = doc.CreateElement("field1", _
                NamespaceManager.LookupNamespace("my"))
                Dim node As XmlNode = group.AppendChild(field)
                node.InnerText = lastname

                field = doc.CreateElement("field2", _
                NamespaceManager.LookupNamespace("my"))
                node = group.AppendChild(field)
                node.InnerText = firstname

                field = doc.CreateElement("field3", _
                NamespaceManager.LookupNamespace("my"))
                node = group.AppendChild(field)
                node.InnerText = email

                doc.AppendChild(group)

                MainDataSource.CreateNavigator().SelectSingleNode( _
                "/my:myFields/my:group1", _
                NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator())

            End Sub

            Private Sub DeleteFirstEmptyItem()

                Dim domNav As XPathNavigator = MainDataSource.CreateNavigator()
                Dim itemNav As XPathNavigator = domNav.SelectSingleNode( _
                "/my:myFields/my:group1/my:group2[1]", _
                NamespaceManager)

                If itemNav IsNot Nothing Then
                    itemNav.DeleteSelf()
                End If
            End Sub
        End Class
    End Namespace 

     

     

  • 02-24-2013 12:19 PM In reply to

    Re: Copying data from secondary data source to repeating table (for Infopath 2010 browser form)

    The delete button is just there for the sample - it is not needed for your solution.
    We have lots of customers using the default data solution to copy values in.

    It's better than code because it doesn't have hardcoded xpaths in it and won't require maintenance. In addition, it doesn't require site collection admin to deploy for 2010 browser forms.

    You just have to set up the rules correctly. We did this for someone else last week. Should take less than an hour to setup.

    Patrick Halstead
    Project Manager at Qdabra
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.