Add a field's value to a Repeating Table field programically. - InfoPath Dev
in

InfoPath Dev

Add a field's value to a Repeating Table field programically.

Last post 08-26-2008 12:33 AM by Shiva. 19 replies.
Page 2 of 2 (20 items) < Previous 1 2
Sort Posts: Previous Next
  • 08-12-2008 01:59 PM In reply to

    Re: Add a field's value to a Repeating Table field programically.

    Hi, Thank you for your reply...

    I have altered the code and it is now working.    Instead of running this code from a button I would like to be able to call it from rules as described  in http://blogs.msdn.com/infopath/archive/2005/06/17/430347.aspx - do you think this is feasible?

    You mentioned copying the from the Sample.xml  How do you do that ?

    Catharine

  • 08-12-2008 03:48 PM In reply to

    Re: Add a field's value to a Repeating Table field programically.

    Hi, Catharine:

    I have not been able to run code using rules that changes the main DOM of the form -- which is what you'd be doing if you called that code from a rule. I know of one series of posts on this where they worked around it by changing a hidden field's value in a rule and then putting the code in the Changed event for that field, which I thought was rather clever.

    Here is some sample code for getting info from the Sample.xml. I'm sorry -- it is in C# and uses the 2003 object model, but I don't have time today to work up a 2007 sample -- if I get a chance tomorrow, I'll post again. This may at least give you an idea, however:

    IXMLDOMDocument2 sampleData;
    sampleData = (IXMLDOMDocument2)thisXDocument.CreateDOM();
    sampleData.async =
    false;
    sampleData.validateOnParse =
    false;
    sampleData.setProperty("SelectionNamespaces", "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\" xmlns:my=\"http://schemas.microsoft.com/office/infopath/2003/myXSD/2008-07-06T22:11:15\" xmlns:xd=\"http://schemas.microsoft.com/office/infopath/2003\"");

    sampleData.load("sampledata.xml");

    IXMLDOMNode newGroup = sampleData.selectSingleNode("/my:myFields/my:Group1/my:Group2/my:Field1").cloneNode(true);

    You'll want to replace the namespaces in sampleData.setProperty with the ones from your sample.xml

    Hilary Stoupa

  • 08-13-2008 11:41 AM In reply to

    • zeroecho
    • Top 500 Contributor
      Male
    • Joined on 10-23-2007
    • Yorkshire, UK
    • Posts 39

    Re: Add a field's value to a Repeating Table field programically.

     Hilary sorted my problem out for those who may find themselves with a similar problem. e.Source.Clone() was what I was after for the entire row :)

  • 08-24-2008 06:13 PM In reply to

    Re: Add a field's value to a Repeating Table field programically.

    Well -- I'm afraid it took me quite a bit longer to get back to this, but so that it is posted somewhere, here is a sample that gets sampledata.xml using the 2007 object model:

    XPathDocument sampleData = new XPathDocument(this.Template.OpenFileFromPackage("sampledata.xml"));
    XPathNavigator newGroup = sampleData.CreateNavigator().SelectSingleNode("/my:myFields/my:topGroup/my:repeatingGroup", NamespaceManager).Clone();

    Note the OpenFileFromPackage method -- it took me a bit to find it, but I can already see it is going to be *very* handy...

    Edit:
    After I revisted this, I discovered that XPathDocument is read-only! So, if you clone from it, you'll not be able to set values in your new group. Use this instead: 
                //get sampledata
                XmlDocument sampleData = new XmlDocument();
                sampleData.Load(this.Template.OpenFileFromPackage("sampledata.xml"));

    Hilary Stoupa

  • 08-26-2008 12:33 AM In reply to

    • Shiva
    • Top 25 Contributor
    • Joined on 04-15-2005
    • India
    • Posts 694

    Re: Add a field's value to a Repeating Table field programically.

    Hello,

    Here is the code you have to write in your onClick Event,

    IXMLDOMDocument2 sampleDataDom = (IXMLDOMDocument2)thisXDocument.CreateDOM();

    sampleDataDom.async = false;

    sampleDataDom.validateOnParse = false;

    sampleDataDom.setProperty("SelectionNamespaces", "namespace of your form");

    sampleDataDom.load("sampledata.xml");

    IXMLDOMNode perActivityNodeFromSampledata = sampleDataDom.selectSingleNode("/my:TimesheetDetails/my:EmployeeInformation/my:TimeReporting/my:PerActivity").cloneNode(true);

    IXMLDOMNode timeReportingNode = thisXDocument.DOM.selectSingleNode("("/my:TimesheetDetails/my:EmployeeInformation/my:TimeReporting ");

    //Inserting the sample node at first position.

    timeReportingNode.parentNode.insertBefore(perActivityNodeFromSampledata, timeReportingNode);

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