Add a row to a repeating table from javascript - InfoPath Dev
in

InfoPath Dev

Add a row to a repeating table from javascript

Last post 07-13-2007 07:07 AM by Taffman. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-02-2007 10:17 AM

    • Eric
    • Not Ranked
    • Joined on 10-10-2006
    • Posts 24

    Add a row to a repeating table from javascript

    Hello,

    I would like to add a row to a repeating table with javascript and coudn't find any tidbits on google or in the forums.

    Has anyone else done this?

    thanks,

    -Eric

    PS I found the following but coudn't adapt it without seeing the poster's data and form layout:

    ======================

    //get parent row
    var parent = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields//s1:InvoiceCommission");

    //get first row
    var rowOne = parent.selectSingleNode("./s1:InvoiceDetailsRow");

    // Create xsi:nil attribute with the proper namespace.
    var xmlNil = parent.ownerDocument.createNode(2, "xsi:nil", "http://www.w3.org/2001/XMLSchema-instance");
    xmlNil.text = "true";

    //clone the first row
    var rowClone = rowOne.cloneNode(true);

    //reset values
    var description = rowClone.selectSingleNode("s1:Description");
    description.text = "CLONED";
    rowClone.selectSingleNode("s1:IsVatCharged").text = 0;
    rowClone.selectSingleNode("s1:VatAmount").text = 0;

    //nillable: The order is important. Attribute must be removed when setting actual value.
    var amount = rowClone.selectSingleNode("s1:NetAmount");
    amount.text = "";
    amount.setAttributeNode(xmlNil);

    //append row to XML document
    parent.insertBefore(rowClone, rowOne);

    Your XML must ofcourse contain a "seed" row in the table, otherwise there will be nothing to clone. Do not use parent.appendChild() as this can make your XML document invalid against your XSD schema. This will happen when the XSD defines a <xs:sequence> and the row element you add is not at the very end in the schema definition.

    Note that MSXML does not have an .insertAfter() method. The .NET assembly System.Xml does, but this will require you to use managed code in your form, which makes deployment more complicated than a script based solution.

  • 01-02-2007 01:12 PM In reply to

    Re: Add a row to a repeating table from javascript

    Hey Eric,

    This has been discussed several times on the forum and it seems like you have found one of the best code snippets around. If you are having trouble adapting the code found in the post I would suggest downloading the InfoPath SDK (which can be found on a link on the left side of this page) and looking up each of the functions to determine their functionality. After this is done, try writing your own code from scratch instead of copy + pasting.

    If all else fails, you can purchase support hours and we can do it for you.

    http://www.qdabra.com/products.asp?cat=12
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-02-2007 01:44 PM In reply to

    • Eric
    • Not Ranked
    • Joined on 10-10-2006
    • Posts 24

    Re: Add a row to a repeating table from javascript

    Thaks Matt,

    There's nothing inherently wrong with the snippet... it's just useless without the surrounding details. I'm sure everyone here would benefit from a clear example if that's the best snippet to be found.

    I'll continue to monkey around with it when I have bunches of spare time :)

    thanks,

    -Eric
  • 07-13-2007 07:07 AM In reply to

    Re: Add a row to a repeating table from javascript

    Is InvoiceDetailsRow the node name or is it InvoiceDetails and we manually add Row ?
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.