Code to add a new row to a repeating table on a button click - InfoPath Dev
in

InfoPath Dev

Code to add a new row to a repeating table on a button click

Last post 07-27-2007 09:41 AM by Greg Collins. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 07-16-2007 12:14 PM

    Code to add a new row to a repeating table on a button click

    Hello there!

    ive been using infopath fora while now but im having problems with repeating tables,

    i want to create a new row at the botom of a repeating table using JScode or maybe theres a way of using built in features, any insight you have on this lil problem of mine would be most appreciated

    thanks in advance!

     

    ben

  • 07-16-2007 04:03 PM In reply to

    Re: Code to add a new row to a repeating table on a button click

    Repeating tables are only a visual representation of the XML data they are bound to.

    To add a new row, use your code to insert a new row into the XML DOM.

    So, for example if you have:

    <Table>
        <Row attr1="" attr2="" attr3=""/>
        <Row attr1="" attr2="" attr3=""/>
        <Row attr1="" attr2="" attr3=""/>
    </Table>

    as the XML that your table is bound to, then you need to use code to insert another <Row attr1="" attr2="" attr3=""/> into the <Table> node.

    This is just basic XML DOM manipulation--not InfoPath specific. If you need help, look up some XML DOM References.

  • 07-24-2007 05:10 AM In reply to

    Re: Code to add a new row to a repeating table on a button click

    Here is how I insert a new row in my repeating section. 

     

    function insertFindDataOS(pass in your parameters here)
    {
    var Findings = XDocument.DOM.selectSingleNode("/my:IC3/my:CurrentFindings/my:ElemOS");
    var copyFindings = Findings.cloneNode(true);
    var newRepeatRow = XDocument.DOM.createNode(1, "my:Finds_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newConcatRow = XDocument.DOM.createNode(1, "my:FindConcat_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newFindRow = XDocument.DOM.createNode(2, "my:Find_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newFindValueRow = XDocument.DOM.createNode(2, "my:FindValue_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newFindIDRow = XDocument.DOM.createNode(2, "my:FindID_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newElementIDRow = XDocument.DOM.createNode(2, "my:ElementID_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newStatusRow = XDocument.DOM.createNode(2, "my:Status_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newSeverityRow = XDocument.DOM.createNode(2, "my:Severity_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newModRow = XDocument.DOM.createNode(2, "my:Mod_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newMasterRow = XDocument.DOM.createNode(2, "my:Master_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newCatFilterRow = XDocument.DOM.createNode(2, "my:CatFilter_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newICD9Code = XDocument.DOM.createNode(2, "my:ICD9Code_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var newMasterID = XDocument.DOM.createNode(2, "my:MasterID_OS", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-05-25T21:47:45");
    var lastRow = Findings.selectNodes("my:Finds_OS").length;

        XDocument.View.DisableAutoUpdate();

        newRepeatRow.appendChild(newConcatRow);
        newConcatRow.setAttributeNode(newFindRow);
        newConcatRow.setAttributeNode(newFindValueRow);
        newConcatRow.setAttributeNode(newFindIDRow);
        newConcatRow.setAttributeNode(newElementIDRow);
        newConcatRow.setAttributeNode(newStatusRow);
        newConcatRow.setAttributeNode(newSeverityRow);
        newConcatRow.setAttributeNode(newModRow);
        newConcatRow.setAttributeNode(newMasterRow);
        newConcatRow.setAttributeNode(newCatFilterRow);
        newConcatRow.setAttributeNode(newICD9Code);
        newConcatRow.setAttributeNode(newMasterID);
        copyFindings.appendChild(newRepeatRow);
       

        copyFindings.appendChild(newRepeatRow);
        Findings.parentNode.replaceChild(copyFindings,Findings);


        Findings = XDocument.DOM.selectSingleNode(parentPath);
        lastRow = Findings.selectNodes(repeatNodeName).length;
        XDocument.SetNamedNodeProperty(Findings, ctrlID, lastRow);

        XDocument.View.EnableAutoUpdate();
    }


    function btnInsertFindingOS::OnClick(eventObj)
    {
        id = "CTRL388";
        insertFindDataOS(set your parameters here);
    }

     

    Hope this helps 

  • 07-26-2007 05:25 AM In reply to

    Re: Code to add a new row to a repeating table on a button click

    Excellent, thanks muchy for the help and gret example! :D

     

    i got my code to work, basically i copied and tweaked code samples untill they worked

     

     var parent = XDocument.DOM.selectSingleNode("/my:myFields/my:group82");

    var rowOne = parent.selectSingleNode("./my:group83");

    var xmlNil = parent.ownerDocument.createNode(2, "xsi:nil", "http://www.w3.org/2001/XMLSchema-instance"); xmlNil.text = "true"; v

    ar rowClone = rowOne.cloneNode(true);

    rowClone.selectSingleNode("my:Product_c").text = parent.selectSingleNode("../my:group84/my:field389").text;

    rowClone.selectSingleNode("my:ProductType_c").text = parent.selectSingleNode("../my:group84/my:field393").text;

    parent.insertBefore(rowClone, rowOne);

     

    its a bit basic but it works wonders

     

    in the end i added a rule to a button which uses the current function to move data from the current repeating section into a set of hidden textboxes then used the code above to move them to the repeating table

  • 07-27-2007 09:41 AM In reply to

    Re: Code to add a new row to a repeating table on a button click

    Glad to hear you got your problem solved!!
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.