Adding first row to repeating table - InfoPath Dev
in

InfoPath Dev

Adding first row to repeating table

Last post 10-06-2006 09:39 AM by BhailDa. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 10-02-2006 07:23 AM

    Adding first row to repeating table

    I have a main connection that looks like:

    myFields
    dataFields
    d:COE_Employees
    -- some stuff --
    Comments
    -- some attributes --
    QF129
    -- some attributes--


    both Comments and QF129 are repeating. Here is the template.xml view:

    <dfs:dataFields>
    <d:COE_Employees EmployeeKey="" Name="">
    -- other stuff --
    <d:Comments CommentKey="" Engineer="" Date=""
    Comment=""></d:Comments>
    <d:QF129 Employee="" Date=""></d:QF129>
    </d:COE_Employees>
    </dfs:dataFields>


    After the query is issued, there are no QF129 items in the DOM. During the lifetime of the form, I want to add them programmatically but cannot use the cloning method since there aren't any to clone from. Here is the code I have to create the new node and add it to the DOM:

    IXMLDOMNode rootNode = thisXDocument.DOM.selectSingleNode
    ("/dfs:myFields/dfs:dataFields/d:COE_Employees");
    IXMLDOMNode QF129Node = thisXDocument.DOM.createNode(
    DOMNodeType.NODE_ELEMENT, "d:QF129",
    "http://schemas.microsoft.com/office/infopath/2003/ado/datafields");
    IXMLDOMAttribute attr = thisXDocument.DOM.createAttribute
    ("Employee");
    attr.value = rootNode.selectSingleNode("@EmployeeKey").text;
    QF129Node.attributes.setNamedItem(attr);
    attr = thisXDocument.DOM.createAttribute("Date");
    attr.value = thisXDocument.DOM.selectSingleNode
    ("/dfs:myFields/my:WeekEnding").text;
    QF129Node.attributes.setNamedItem(attr);
    rootNode.appendChild(QF129Node);


    The problem is that the call to appendChild fails with an error saying:

    Element 'http://schemas.microsoft.com/office/infopath/2003/ado/datafields}QF129' is unexpected according to content model of parent element 'http://schemas.microsoft.com/office/infopath/2003/ado/dataFields}COE_Employees'.

    So, how do I add the first item for a repeating element programmatically?



  • 10-03-2006 09:14 AM In reply to

    Re: Adding first row to repeating table

    I think the problem with appendChild is that you are making some kind of mistake when you call thisXDocument.DOM.createNode(). There might be some kind of problem with the namespace or something, but this should work if everything is done correctly.

    However, there are a couple of ways to solve this problem:

    1. Create a global IXMLDOMNode variable to hold the clone of the QF129 node, and populate this variable in Onload. This way you will have the clone before it is removed and you will have it for the life of the code since it is a global variable.

    2. Create a temporary DOM and load the xml from the template.xml file.

    Personally, I think the first method is cleaner and easier.

    I hope this helps - good luck!
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-03-2006 09:19 AM In reply to

    Re: Adding first row to repeating table

    In fact last night I got your first option working and this morning your second option. It still seems like creating the node should work but I sure don't see the mistake.

    Thank you for your reply.
  • 10-06-2006 09:39 AM In reply to

    • BhailDa
    • Not Ranked
    • Joined on 10-06-2006
    • United Kingdom
    • Posts 13

    Re: Adding first row to repeating table

    I has a simialr problem within InfoPath 2007 Managed code. Code solution:

    // Now Create a new row
    // Find first Instance of repeat nodes and create entry before.
    xNode = xNavigator.SelectSingleNode("//History", this.NamespaceManager);
    string sNewRow = string.Format("<History><User>{0}</User><ChangeType>{1}</ChangeType><CreateDate>{2}</CreateDate></History>", sUser, sChangeType, sCreateDate);
    xNode.InsertBefore(sNewRow);
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.