locked
How come I can't add rows with code based on my structure? RRS feed

  • Question

  • Hi Guys,

    I'm a newbie with all this, so pardon the simple question and I don't know if this is an XML problem or InfoPath

    I have an InfoPath form that is structured like this:

    root
        Details
           RepTable
              Field1
              Field2
              Field3
            RepTable2
              FirstField
              
    I have code this code that DOESN'T work (changed it a bit, got it from here: http://sharepoint.orcinus-orca.eu/archives/17)

    XPathNavigator xPathNavi = MainDataSource.CreateNavigator();
          XPathNavigator details = xPathNavi.SelectSingleNode("/my:root/my:Details", NamespaceManager);
          XPathNavigator repTable = details.SelectSingleNode("my:RepTable", NamespaceManager);
          XPathNavigator node;
    
           XPathNavigator repTable2 = details.SelectSingleNode("my:RepTable2", NamespaceManager);
              
          int counter = 0;
           
         
          for (int i=0; i<2; i++)
          {       
            node = repTable.Clone();
    
            node.SelectSingleNode("my:FieldA", NamespaceManager).SetValue("FieldA - Row " + i.ToString());
            node.SelectSingleNode("my:FieldB", NamespaceManager).SetValue("FieldB - Row " + i.ToString());
            node.SelectSingleNode("my:FieldC", NamespaceManager).SetValue("FieldC - Row " + i.ToString());      
            details.AppendChild(node);
    
            counter += 1;
          }
    

       
    But, if I change the structure to look like this, the identical code works fine:
    root
        Details
            RepTable2
              FirstField   
           RepTable
              Field1
              Field2
              Field3
             
    Since my real structure is much more complicated and not easy to move around, how can I get the code to work with the first structure I showed?

    Thanks so very much!!!

    -J

    Tuesday, March 22, 2011 5:42 PM

Answers

  • Jenna:

    If am understanding you data source structure, RepTable and RepTable2 are both repeating groups under the Details group.

    I found that you cannot have more than 1 repeating node in a group if you want to use AppendChild.

    You may have to change your data source to look something like this:

    <root>
         <Details> (Group)
              <RepTable> (Group)
                   <RepTableRow> (Repeating Group)
                        <Field1>
                        <Field2>
                        <Field3>
              <RepTable2> (Group)
                   <RepTable2Row> (Repeating Group)
                        <FirstField>
    

    Hope this helps

    Ed

     

    • Marked as answer by Jenna_Fire Wednesday, March 23, 2011 8:04 PM
    Tuesday, March 22, 2011 7:47 PM

All replies

  • Jenna:

    If am understanding you data source structure, RepTable and RepTable2 are both repeating groups under the Details group.

    I found that you cannot have more than 1 repeating node in a group if you want to use AppendChild.

    You may have to change your data source to look something like this:

    <root>
         <Details> (Group)
              <RepTable> (Group)
                   <RepTableRow> (Repeating Group)
                        <Field1>
                        <Field2>
                        <Field3>
              <RepTable2> (Group)
                   <RepTable2Row> (Repeating Group)
                        <FirstField>
    

    Hope this helps

    Ed

     

    • Marked as answer by Jenna_Fire Wednesday, March 23, 2011 8:04 PM
    Tuesday, March 22, 2011 7:47 PM
  • Ed,

    Yes, that definitely helps. It now works! I think it is kinda silly that just by moving the InfoPath SQL around (and placing the group at the bottom) that it worked. Whatever, it is working for me now.

     

    Thanks so much for the help.

    -J

    Wednesday, March 23, 2011 8:06 PM