Code to add rows at the end of repeating table - InfoPath Dev
in

InfoPath Dev

Code to add rows at the end of repeating table

Last post 11-15-2005 08:26 AM by franck. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 11-13-2005 06:34 AM

    Code to add rows at the end of repeating table

    Hi,

    I have a repeating table that is used to capture the list of approvers who approve the form in the work flow.
    So when each approver selects his superior,I need to add the superior name to this repeating table.

    I need a code sample to append a row at the bottom of the repeating table which already contains some number of rows.

    Any help greatly appreciated.

    regards,
    Abhishek.
  • 11-13-2005 06:48 AM In reply to

    Re: Code to add rows at the end of repeating table

    This is in VBScript but you can translate it pretty easily to whatever language.

    For sXML pass in an XML string for the group item like:

    sXML = "<Approver><fname></fname><lname></lname><email></email></Approver>"

    For sParentNodePath pass in the XPath string for the Approver repeating group.

    sParentNodePath = "//my:Approvers"

    Sub CreateRow(sXML, sParentNodePath)

    'Create a new row
    dim oXml
    set oXml = XDocument.CreateDOM()
    oXml.async = false
    oXml.loadXML(sXML)

    'add the row to the DOM
    XDocument.DOM.selectSingleNode(sParentNodePath).appendChild(oXml.documentElement)

    End Sub
    Jason
    http://www.k2distillery.com/
  • 11-13-2005 10:08 AM In reply to

    Re: Code to add rows at the end of repeating table

    Hi,

    Here is a C# sample is you need managed code instead:

    IXMLDOMDocument2 templateDom = (IXMLDOMDocument2)thisXDocument.CreateDOM();
    templateDom.validateOnParse = false;
    templateDom.load("template.xml");
    templateDom.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-10-10T17-59-19'");
    IXMLDOMNode oTemplateGrp = templateDom.selectSingleNode("/my:myFields/my:group1/my:group2");
    IXMLDOMNode oTemplateNode = oTemplateGrp.cloneNode(true);
    IXMLDOMNode oGroup1 = thisXDocument.DOM.selectSingleNode("/my:myFields/my:group1");
    oGroup1.appendChild(oTemplateNode);

    Regards,

    Franck Dauché
  • 11-13-2005 10:08 PM In reply to

    Re: Code to add rows at the end of repeating table

    Thank you very much guys.But I have a problem when using the same code as the one given by Frank


    Case1
    The structure of my data source is as follows

    --PR_Form //root
    --Executers //This is a group
    --Approvers //This is a group
    ---Approver //This is a repeating group
    --- ApproverName //Field

    Now in the onclick event if I write the code given by Franck as follows..
    IXMLDOMDocument2 templateDom = (IXMLDOMDocument2)thisXDocument.CreateDOM();

    templateDom.validateOnParse = false;
    templateDom.load("template.xml");

    templateDom.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-02T09:58:08'");

    IXMLDOMNode oTemplateGrp = templateDom.selectSingleNode("/my:PR_Form/my:Executers/my:Approvers/my:Approver");

    IXMLDOMNode oTemplateNode = oTemplateGrp.cloneNode(true);

    IXMLDOMNode oGroup1 = thisXDocument.DOM.selectSingleNode("/my:PR_Form/my:Executers/my:Approvers");

    oGroup1.appendChild(oTemplateNode);

    But when debugging,after the last line i.e "oGroup1.appendChild(oTemplateNode);",
    Infopath throws an error stating

    System.Runtime.InteropServices.COMException
    Element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-02T09:58:08}Approver' is unexpected according to content model of parent element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-11-02T09:58:08}Approvers'.

    at Microsoft.Office.Interop.InfoPath.SemiTrust.IXMLDOMNode.appendChild(IXMLDOMNode newChild)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.appendChild(IXMLDOMNode newChild)
    at Microsoft.Office.Interop.InfoPath.SemiTrust.DOMNodeWrapper.appendChild(IXMLDOMNode newChild)
    at PR_Automation.PR_Automation.CTRL16_40_OnClick(DocActionEvent e) in e:\1pr_automation\pr_automation\formcode.cs:line 123
    at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)


    Out of curiosity,I used "templateDom.selectSingleNode" instead of "thisXDocument.Dom.selectSingleNode" when creating the oGroup1 node.Surprisingly Infopath did not throw the error nor did I get the desired results.
    So I think its got something to do with setting namespace or some thing like that.
    Need ur help guys.

    Regards,
    Abhishek
  • 11-14-2005 06:35 AM In reply to

    Re: Code to add rows at the end of repeating table

    Hi Abhishek,

    Something may be wrong with your schema. To check that it is working:
    - Create a new blank form.
    - Drag-n-Drop a Repeating Section (from your "Controls" Task Pane) on your main View.
    - Inside the repeating section, Drag-n-Drop 1 textboxe
    You should have:
    myFields
    group1
    group2 <-- repeating
    field1

    Use the code that I posted (make sure to update the namespace). It will work.
    Now, compare the schema of that form with your.

    Now, you can't replace the template by the DOM as you described at the end of your post.

    Regards,

    Franck Dauché
  • 11-15-2005 07:50 AM In reply to

    Re: Code to add rows at the end of repeating table

    Thank you very very much Frank.

    Something had gone wrong with my schema.Becoz I deleted the groups and fields and added the same thing again and it worked.
    And I really dont know as to how something can go wrong with my schema without me doing anything to it.

    Anyway thank u very much.
    U guys make a lot of guys like me happy by providing solutions.
    Just cant tell u how releived I am.
    regards,
    Abhishek
  • 11-15-2005 08:26 AM In reply to

    Re: Code to add rows at the end of repeating table

    You are welcome.

    Good luck with your InfoPath Developments. Don't hesitate to come back and to open a new thread if you have any other issue.
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.