Loading secondary datasource into form - InfoPath Dev
in

InfoPath Dev

Loading secondary datasource into form

Last post 06-27-2007 02:37 PM by Matt Faus. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 06-26-2007 01:49 AM

    • spudy
    • Top 150 Contributor
    • Joined on 03-23-2006
    • United Kingdom
    • Posts 67

    Loading secondary datasource into form

    I have been using a post by Matt http://www.infopathdev.com/blogs/matt/archive/2005/11/29/Repeat-Table-Headers-Across-Multiple-Printed-Pages.aspx for some of the code I have used to copy all nodes from a secondary datasource into a form.

    The code is as follows:

        var domDataLibrary = XDocument.GetDOM("Data Library");    
        // Source nodes.
        var oDataItems = domDataLibrary.selectNodes("/ds1:Schedule/ds1:List/ds1:Item");

        // Get the node list.
        var oRows = XDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2");

        // Save a sample node from this list
        var oSampleRow = oRows.nextNode();

        // Loop through all source nodes.
        while(oSrc = oDataItems.nextNode())
        {    
            var oNewRow = oSampleRow.cloneNode(true); 

            oNewRow.selectSingleNode("my:field2").nodeTypedValue = oSrc.selectSingleNode("ds1:Code").nodeTypedValue;
            oNewRow.selectSingleNode("my:field3").nodeTypedValue = oSrc.selectSingleNode("ds1:Description").nodeTypedValue;
            oNewRow.selectSingleNode("my:field4").nodeTypedValue = oSrc.selectSingleNode("ds1:Unit").nodeTypedValue;
            oNewRow.selectSingleNode("my:field5").nodeTypedValue = oSrc.selectSingleNode("ds1:Price").nodeTypedValue;

            // Add the row to the table (where the code fails)
            XDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2").appendChild(oNewRow);

        } }

     The code fails with the following error:

    The following error occurred:

    Element '{http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-06-19T14:57:44}group2' is unexpected according to content model of parent element '{http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-06-19T14:57:44}group2'.

    File:script.js
    Line:121

    Any help on this one would be great.....something simple no doubt ...

  • 06-26-2007 07:19 AM In reply to

    Re: Loading secondary datasource into form

    You're trying to add it in the wrong place, change the line to this:

    // Add the row to the table (where the code fails)
    XDocument.DOM.selectSingleNode("/my:myFields/my:group1").appendChild(oNewRow);

    Good luck on this, though! It is quite meticulous.

    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-26-2007 08:54 AM In reply to

    • spudy
    • Top 150 Contributor
    • Joined on 03-23-2006
    • United Kingdom
    • Posts 67

    Re: Loading secondary datasource into form

    Matt,

    Thanks for the response. I tried that but the same error is displayed with the exception that the parent element changes to reflect the change you mentioned. Your good luck message owing the to meticulousness of this code does cause concern for me. Pethaps there is an easier way of doing this?

    thanks

  • 06-26-2007 11:22 AM In reply to

    Re: Loading secondary datasource into form

    Weird.  This should be a pretty simple mistake, the schemas are not matching up for some reason, but I cannot figure out why from what you have shown me.  I would suggest outputting the .xml of the various objects and see what you can deduce.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 06-27-2007 09:30 AM In reply to

    • spudy
    • Top 150 Contributor
    • Joined on 03-23-2006
    • United Kingdom
    • Posts 67

    Re: Loading secondary datasource into form

    Found the problem to be another group beneath Group2 in the main data source. Once deleted or moved to higher in the tree above Group 2 then this cured the problem.

    thanks for your assistance again Matt.

  • 06-27-2007 02:37 PM In reply to

    Re: Loading secondary datasource into form

    Cool, glad you got everything figured out! Let us know if you need anything else.
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.