Populate main table from secondary table - InfoPath Dev
in

InfoPath Dev

Having trouble finding a blog or post that answers your question? Check out our Custom Search Page

Populate main table from secondary table

Last post 01-10-2014 08:49 AM by hayer89. 16 replies.
Page 1 of 2 (17 items) 1 2 Next >
Sort Posts: Previous Next
  • 12-19-2013 06:45 AM

    Populate main table from secondary table

    I am trying to populate My main table which only consists of one field from a secondary table automatically when a button is pressed. It is throwing up an error on this line:

    MainDataSource.CreateNavigator().SelectSingleNode( _

    "/dfs:myFields/dfs:dataFields", _

    NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator())

    Any help would be much appreciated :)

    Filed under: , , ,
  • 12-19-2013 09:26 PM In reply to

    Re: Populate main table from secondary table

    Hi hayer89,

    Is your button located within the repeating table? If not, then it might not be able to locate or identify which row you would like to copy. Please check the sample form I am attaching and see if this approach will work for you, or send us a sample so we could investigate further.

    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 12-30-2013 04:53 AM In reply to

    Re: Populate main table from secondary table

    Thanks for your reply donstephen, just to answer your question my button is located within the repeating table, I am however unable to open your sample form as I only have InfoPath 2007 SP3 to work with.

    The code is:

    Public Sub CTRL151_4_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

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

    'Retrieve the rows of the secondary data source'

    Dim rows As XPathNodeIterator = secDSNav.Select( _

    "/dfs:myFields/dfs:dataFields/d:SecondaryTable", _

    NamespaceManager)

    'Loop through the rows of the secondary data source and fill the repeating table '

    While rows.MoveNext()

    Dim ID As String = rows.Current.SelectSingleNode( _

    "@SecondID", NamespaceManager).Value

    ' Add the item to the repeating table '

    AddItem(ID)

    End While

    ' Remove the first empty item from the repeating table '

    DeleteFirstEmptyItem()

    End Sub

    Private Sub AddItem( _

    ByVal ID As String)

    Dim doc As XmlDocument = New XmlDocument()

    Dim group As XmlNode = doc.CreateElement("MainTable", _

    NamespaceManager.LookupNamespace("d"))

    Dim field As XmlNode = doc.CreateElement("MainID", _

    NamespaceManager.LookupNamespace("@"))

    Dim node As XmlNode = group.AppendChild(field)

    node.InnerText = ID

    doc.AppendChild(group)

    MainDataSource.CreateNavigator().SelectSingleNode( _

    "/dfs:myFields/dfs:dataFields", _

    NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator())

    End Sub

    Private Sub DeleteFirstEmptyItem()

    Dim domNav As XPathNavigator = MainDataSource.CreateNavigator()

    Dim itemNav As XPathNavigator = domNav.SelectSingleNode( _

    "/dfs:myFields/dfs:dataFields/@MainID[1]", _

    NamespaceManager)

    If itemNav IsNot Nothing Then

    itemNav.DeleteSelf()

    End If

    End Sub

    However my code works when I try to populate custom made Fields and Groups, here is my code:

    Public Sub CTRL151_4_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

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

    ' Retrieve the rows of the secondary data source

    Dim rows As XPathNodeIterator = secDSNav.Select( _

    "/dfs:myFields/dfs:dataFields/d:SecondaryTable", _

    NamespaceManager)

    ' Loop through the rows of the secondary data source and fill the repeating table

    While rows.MoveNext()

    Dim ID As String = rows.Current.SelectSingleNode( _

    "@SecondID", NamespaceManager).Value

    ' Add the item to the repeating table

    AddItem(ID)

    End While

    ' Remove the first empty item from the repeating table

    DeleteFirstEmptyItem()

    End Sub

    Private Sub AddItem( _

    ByVal ID As String)

    Dim doc As XmlDocument = New XmlDocument()

    Dim group As XmlNode = doc.CreateElement("group2", _

    NamespaceManager.LookupNamespace("my"))

    Dim field As XmlNode = doc.CreateElement("MainID", _

    NamespaceManager.LookupNamespace("my"))

    Dim node As XmlNode = group.AppendChild(field)

    node.InnerText = ID

    doc.AppendChild(group)

    MainDataSource.CreateNavigator().SelectSingleNode( _

    "/dfs: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( _

    "/dfs:myFields/my:group1/my:group2/my:MainID[1]", _

    NamespaceManager)

    If itemNav IsNot Nothing Then

    itemNav.DeleteSelf()

    End If

    End Sub

    End Class

    But what I really need is to populate my Main Data Connection so that I can Submit all of the ID's.

    Filed under: , , ,
  • 12-30-2013 05:06 AM In reply to

    Re: Populate main table from secondary table

    Apologies for that. Here's the form converted to InfoPath 2007. Please check if this approach is close to what you're looking for. If not, kindly attach a copy or a sample of your form so I can get a better idea of what you need.

    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 12-30-2013 05:14 AM In reply to

    Re: Populate main table from secondary table

    Thanks donstephen, the approach is what I am looking for, however I need to populate the same field multiple times from the Secondary data source.
    Filed under: , , ,
  • 12-30-2013 06:32 AM In reply to

    Re: Populate main table from secondary table

    Thank you for the additional information. I am attaching an updated form. Please check if this approach works for you.

    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 12-31-2013 01:07 AM In reply to

    Re: Populate main table from secondary table

    Thank you for your help donstephen, but I was looking for the secondary data source fields to be submitted into the main data connection into separate records, not one large concatenated entry, please see the attached example of what I am trying to do.

    Basically trying to copy the fields in a secondary data source like for like and submitting them into my main data connection as separate records. So if I have 20 colours names in my secondary data source, I want those 20 colour names to be submitted into my main data connection as 20 records. I feel that the VB code I have been working on is almost complete but it is throwing up an error. Could you please take a look :)

    Thanks you once again, your help throughout has been much appreciated

    Filed under: , , ,
  • 12-31-2013 01:55 AM In reply to

    Re: Populate main table from secondary table

    Please check the two approaches we have for copying repeating tables on the attached form. The first approach uses a trigger technique, while the second one uses qRules' Insert command.

    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 12-31-2013 02:03 AM In reply to

    Re: Populate main table from secondary table

    Thanks for the reply donstephen, could you please resend that form in InfoPath 2007 :)
  • 12-31-2013 02:08 AM In reply to

    Re: Populate main table from secondary table

    Whoops. Didn't notice that. I've updated the previous attachment to 2007.

    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 12-31-2013 06:36 AM In reply to

    Re: Populate main table from secondary table

    I'm trying to use the second approach that uses the qRules' Insert command, but I am having difficulty getting it to work. Maybe its because I am using a database as the main connection instead of an XML connection? I've attached my InfoPath form with the QdabraRules inside the form.

    Would really appreciate it if you could have a look :)

    Filed under: , , ,
  • 01-02-2014 05:05 PM In reply to

    Re: Populate main table from secondary table

    It seems that you’ll need to manually add the qRules DLL instead of injecting. Please refer to this guide for the steps. Also, there were some rules which were omitted at target the repeating group (see image below). 

    Hope this helps.

    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 01-10-2014 03:00 AM In reply to

    Re: Populate main table from secondary table

    Thanks donstephen, but I do not have qRules, is there any way to do it without?
  • 01-10-2014 05:00 AM In reply to

    Re: Populate main table from secondary table

    InfoPath's built in functionality has its limitations, and automatically inserting multiple rows is one of them. Please check the form I am attaching for the copy table approach without using qRules. I hope this helps.
    Don Stephen Lambatin / Support Engineer
    Qdabra Software
  • 01-10-2014 06:44 AM In reply to

    Re: Populate main table from secondary table

    The problem with that approach is that I am trying to submit into a database table, meaning I am unable to add the "count" and "lastitem" fields .. which are needed :(

    Unless there's a way to submit user created fields into the database table?

Page 1 of 2 (17 items) 1 2 Next >
Copyright © 2003-2017 Qdabra Software. All rights reserved.
View our Terms of Use.