Using deep parameter of clonenode to recursively clone all descendant nodes - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Using deep parameter of clonenode to recursively clone all descendant nodes

Last post 08-28-2007 07:52 AM by spudy. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 08-28-2007 02:48 AM

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

    Using deep parameter of clonenode to recursively clone all descendant nodes

    Can anyone help with this? 

    I am using clonenode to create a same as function within my form. Once a user has gathered lots of information and then wishes to start a new record but using previous detail as a starting point,a same as function is used calling the clone function. 

    The code for performing the clone does work but it is not working for repeating groups within the parent. For example:

    myFields/FirstGroup/FirstRepeatingGroup contains a group /SecondGroup/SecondRepeatingGroup - if rows exist in the SecondRepeatingGroup they do not get cloned - only the first blank row exists.

    The clonenode is using (true) to set the deep parameter but does not seem to clone the repeating group.

    The code goes like this:

    var nodeList = XDocument.DOM.selectNodes("my:myFields/my:FirstGroup/my:FirstRepeatingGroup");

    for ( var i = 0; i < nodeList.length; i++)

    {

     var RowIDfield = nodeList.item(i).selectSingleNode("my:RowID");

    //Check if ID matches the Same As selection

    if ( RowIDfield.nodeTypedValue == tempNode.text )

    {

    var oldRow = nodeList.item(i).selectSingleNode("//my:FirstGroup/my:FirstRepeatingGroup");

    var newRow = oldRow.cloneNode(true);

    }

     

    Regards Spudy

  • 08-28-2007 04:47 AM In reply to

    Re: Using deep parameter of clonenode to recursively clone all descendant nodes

    Hi,
    When deep is set to true then repeating nodes also get copied. Code provided below does not give anough information. If you can provide with more code then we might be able to help you.

  • 08-28-2007 07:52 AM In reply to

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

    Re: Using deep parameter of clonenode to recursively clone all descendant nodes

    When I looked at the code to figure out what would be needed to replicate this issue in order to post more information here I discovered the problem!

    There is not much that can beat taking a fresh look from a different perspective.

    My clone node line of code:

    var oldRow = nodeList.item(i).selectSingleNode("//my:FirstGroup/my:FirstRepeatingGroup");

    should have been

    var oldRow = nodeList.item(i)

     There after I simply added the clone node:

     var parent = oldRow.parentNode;

    var tempValues = XDocument.DOM.selectSingleNode("//my:TemporaryValues");

    parent.insertBefore(newRow, tempValues);

    Thankyou for making me revisit from a different angle.......

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