Copy Secondary Data source to Main - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Copy Secondary Data source to Main

Last post 06-26-2008 02:38 PM by Hilary Stoupa. 13 replies.
Page 1 of 1 (14 items)
Sort Posts: Previous Next
  • 06-25-2008 12:30 PM

    • mmarvi
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 9

    Copy Secondary Data source to Main

    I've found code to do the captioned job, but I have some kind of problem.

     

    Here is my code

    // Get a copy of the main DOM node.
    var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:Table_StaffProfiles").cloneNode(true);

    // Clear the main DOM nodes.
    XDocument.DOM.selectNodes("/my:myFields/my:Table_StaffProfiles").removeAll();

    clone.selectSingleNode("my:EmployeeName_Full").text = "x";
    clone.selectSingleNode("my:EmployeeName_SP").text = "";
    clone.selectSingleNode("my:EmployeeAddressLine1").text = "";
    clone.selectSingleNode("my:EmployeeAddressLine2").text = "";
    clone.selectSingleNode("my:EmployeeAddressCity").text = "";
    clone.selectSingleNode("my:EmployeeAddressState_Region").text = "";
    clone.selectSingleNode("my:EmployeeTitle").text = "";
    clone.selectSingleNode("my:EmployeeEmailAddress").text = "";
    XDocument.DOM.selectSingleNode("my:myFields").appendChild(clone.cloneNode(true));


    // Get the SharePointList DOM
    var oSharePointDom = XDocument.GetDOM("Staff Profiles");
    // Setup the Namespaces
    oSharePointDom.setProperty("SelectionNamespaces", 'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
    // Loop through all of the items in the SharePoint List
    var nlSharedItems = oSharePointDom.selectNodes("/dfs:myFields/dfs:dataFields/dfs:Staff_Profiles");

    while( (nSharedItem = nlSharedItems.nextNode() ) != null )
    {
    // Create a new row from the sample

    var clone = XDocument.DOM.selectSingleNode("/my:myFields/my:Table_StaffProfiles").cloneNode(true);
    clone.selectSingleNode("my:EmployeeName_Full").text = nSharedItem.selectSingleNode("EmployeeName_Full").text;
    clone.selectSingleNode("my:EmployeeName_SP").text = nSharedItem.selectSingleNode("EmployeeName_SP").text;
    clone.selectSingleNode("my:EmployeeAddressLine1").text = nSharedItem.selectSingleNode("EmployeeAddressLine1").text;
    clone.selectSingleNode("my:EmployeeAddressLine2").text = nSharedItem.selectSingleNode("EmployeeAddressLine2").text;
    clone.selectSingleNode("my:EmployeeAddressCity").text = nSharedItem.selectSingleNode("EmployeeAddressCity").text;
    clone.selectSingleNode("my:EmployeeAddressState_Region").text = nSharedItem.selectSingleNode("mployeeAddressState_Region").text;
    clone.selectSingleNode("my:EmployeeTitle").text = nSharedItem.selectSingleNode("EmployeeTitle").text;
    clone.selectSingleNode("my:EmployeeEmailAddress").text = nSharedItem.selectSingleNode("EmployeeEmailAddress").text;
    XDocument.DOM.selectSingleNode("my:myFields").appendChild(clone.cloneNode(true));
    }

    I get an Error on the Italic Lines. It seems to be nSharedItem.selectSingleNode("EmployeeName_Full").text causing the problem.

    The error is

    The following error occurred:

    Object required
    File:script.js
    Line:186 is the first italic line. If I replace the nSharedItem.selectSingleNode("EmployeeName_Full").text with plain text, I get no problem, and it iterates through the whole data set.

    What am I doing wrong?

     

    Mo

  • 06-25-2008 03:35 PM In reply to

    Re: Copy Secondary Data source to Main

    Hi:

    Your object required error (and your test where you replace the problematic line) indicates that nSharedItem.selectSingleNode("EmployeeName_Full").text is returning null, hence there is no object. Usually when I have that issue it is because I have a mistake in my xpath pointing to the node I want -- incorrect spelling or capitalization or something. I'm sure you have checked that already. Is there anything special about that field in your list? Is it just a regular text field?

    Hilary Stoupa

  • 06-25-2008 04:14 PM In reply to

    • mmarvi
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 9

    Re: Copy Secondary Data source to Main

    It's just a regular text field.

    I have the object, because, if I comment out the offending lines, and set the clone to add straight text (""PP") I end up with a string of records with "PP".

    This is depressing.

     M

  • 06-25-2008 04:34 PM In reply to

    Re: Copy Secondary Data source to Main

    You have the object in the first bit:

    clone.selectSingleNode("my:EmployeeName_Full").text

    But I mean this line isn't returning an object:

    nSharedItem.selectSingleNode("EmployeeName_Full").text

    exactly for the reason you state, that you can enter text instead of the line above and not get an error. That's why I was wondering about it being the xpath in nSharedItem.selectSingleNode("EmployeeName_Full").text.  Have you tried popping up an alert box to show the value of that node, or debugging? And I agree -- it is always hard when you are really close to getting something and one last thing isn't behaving.

    Hilary Stoupa

  • 06-26-2008 06:19 AM In reply to

    • mmarvi
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 9

    Re: Copy Secondary Data source to Main

    Is there any way to loop through all the column names of nSharedItem?

    That may help me with the syntax of whats between the ().

     

    M

  • 06-26-2008 09:20 AM In reply to

    Re: Copy Secondary Data source to Main

    Hi:

    I did this to iterate and show values for fields under a group:

    var group = XDocument.DOM.selectNodes("/my:myFields/my:group1/my:group2");
        while( (groupfield = group.nextNode()) != null ){
            if (groupfield.hasChildNodes()) {
                var i = 0 
                for (var i = 0; i < groupfield.childNodes.length; i++){
                     XDocument.UI.Alert(groupfield.childNodes[i].nodeName);
                }
            }
        }

    This also pops up #text for the text content, which you can ignore, but every other alert will show you a field name.

    Hilary Stoupa

    Filed under:
  • 06-26-2008 09:44 AM In reply to

    • mmarvi
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 9

    Re: Copy Secondary Data source to Main

    This is wierd,

    I added  XDocument.UI.Alert(groupfield.hasChildNodes());

    Just before if (groupfield.hasChildNodes()) , and get a string of falses!

     Could this be because I am using a Secondary Data Source?

    var oSharePointDom = XDocument.GetDOM("Staff Profiles");
    oSharePointDom.setProperty("SelectionNamespaces", 'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution"');
    var group = oSharePointDom.selectNodes("/dfs:myFields/dfs:dataFields/dfs:Staff_Profiles");
        while( (groupfield = group.nextNode()) != null ){
      XDocument.UI.Alert(groupfield.hasChildNodes());
            if (groupfield.hasChildNodes()) {
                var i = 0
                for (var i = 0; i < groupfield.childNodes.length; i++){
                     XDocument.UI.Alert(groupfield.childNodes[i].nodeName);
                }
            }
        }
     

     

     M

  • 06-26-2008 10:19 AM In reply to

    Re: Copy Secondary Data source to Main

    Do you mind posting a screen shot that shows your secondary data source schema from the taskpane in InfoPath?

    Hilary Stoupa

  • 06-26-2008 10:49 AM In reply to

    • mmarvi
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 9

    Re: Copy Secondary Data source to Main

  • 06-26-2008 11:57 AM In reply to

    Re: Copy Secondary Data source to Main

    Are you using IP 2007? Could you rightclick EmployeeName_Full and copy the xpath?

    Hilary Stoupa

  • 06-26-2008 12:45 PM In reply to

    • mmarvi
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 9

    Re: Copy Secondary Data source to Main

    Sorry, IP 2003

    M

     

    Would it help to extract the files and review the xsd file?

    <?xml version="1.0"?>
    <xsd:schema elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution">
     <xsd:element name="myFields">
      <xsd:complexType>
       <xsd:sequence>
        <xsd:element name="dataFields">
         <xsd:complexType>
          <xsd:sequence>
           <xsd:element name="Staff_Profiles" minOccurs="0" maxOccurs="unbounded">
            <xsd:complexType>
             <xsd:attribute name="EmployeeName_Full" type="xsd:string"></xsd:attribute>
             <xsd:attribute name="EmployeeName_SP" type="xsd:string"></xsd:attribute>
             <xsd:attribute name="EmployeeAddressLine1" type="xsd:string"></xsd:attribute>
             <xsd:attribute name="EmployeeAddressLine2" type="xsd:string"></xsd:attribute>
             <xsd:attribute name="EmployeeAddressCity" type="xsd:string"></xsd:attribute>
             <xsd:attribute name="EmployeeAddressState_Region" type="xsd:string"></xsd:attribute>
             <xsd:attribute name="EmployeeTitle" type="xsd:string"></xsd:attribute>
             <xsd:attribute name="EmployeeEmailAddress" type="xsd:string"></xsd:attribute>
            </xsd:complexType>
           </xsd:element>
          </xsd:sequence>
         </xsd:complexType>
        </xsd:element>
       </xsd:sequence>
      </xsd:complexType>
     </xsd:element>
    </xsd:schema>

  • 06-26-2008 01:12 PM In reply to

    Re: Copy Secondary Data source to Main

    Okay, they are attributes. Try this "@EmployeeName_Full"

    Hilary Stoupa

  • 06-26-2008 01:31 PM In reply to

    • mmarvi
    • Not Ranked
    • Joined on 06-25-2008
    • Posts 9

    Re: Copy Secondary Data source to Main

    I used this

    nSharedItem.selectSingleNode("@EmployeeName_Full").text

    And still got the error.

    I tried this, on a wild hunch

    nSharedItem.selectSingleNode("@EmployeeName_Full")

    And got type mismatch?

     Any Ideas?

     

    M

  • 06-26-2008 02:38 PM In reply to

    Re: Copy Secondary Data source to Main

    Well, the type mismatch is because your second line is selecting a node, and then you are trying to set a text field to a node... thus, they are not the same type. I am pretty much stumped at this point -- I had thought your problem would be due to the xpath ("EmployeeName_Full") being incorrect, but really, since your first block of code works fine for all the fields except "EmployeeName_Full" and you aren't using the attribute symbol ("@") in any of the rest of them, I am afraid I am out of ideas.

    Hilary Stoupa

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