Inserting into Repeating Table Programmatically - InfoPath Dev
in

InfoPath Dev

Inserting into Repeating Table Programmatically

Last post 03-10-2006 02:04 AM by vasanthaprabu. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 04-14-2005 12:34 AM

    Inserting into Repeating Table Programmatically


    Let say I have the following data source structure:
    1. myFields
    1.1 logGroup
    1.1.1 logEntries (the repeating table)
    1.1.1.1 name (the 1st field in the repeating table)
    1.1.1.2 age (the 2nd field in the repeating table)

    Does anyone know how to insert a row programmatically into a repeating table, such that each row to be inserted into repeating table logEntries contain the field "name" and "age" ?

    thank you :)
  • 04-14-2005 02:26 AM In reply to

    Re: Inserting into Repeating Table Programmatically

    oh yeah forgot to mention, i realised i need to use:

    XDocument.View.ExecuteAction("xCollection::insert", "<table_name>");

    but where/when to specify the field values to be inserted?
  • 04-14-2005 12:41 PM In reply to

    Re: Inserting into Repeating Table Programmatically

    Here is one way of adding a new row to the repeating table.

    //write get the XML of repeating node into a string
    string sRepeatingXml = "<LogEntries><name>NameValue<name><age>Agevalue</age><LogEntries>";

    //create a Dom for the XMLNode
    IXMLDOMDocument oXml = thisXDocument.CreateDOM();
    oXml.async = false;
    oXml.loadXML(sRepeatingXml);

    //Get the Parent of the repeating table
    ixmldomNode parentofRepeatingNode = getNode("logGroup/logEntries");

    //append the repeating XML Element to the Parent node
    parentofRepeatingNode.appendChild(oXml.documentElement);

    Agni
    InfopathDev India
  • 04-14-2005 07:57 PM In reply to

    Re: Inserting into Repeating Table Programmatically

    Hi Agni,
    thanks for the reply.

    I've included the code you gave me, but it throws me an error saying something that the element "LogEntries" entered is not as infopath expected due to the namespace naming difference i suppose, even after I setProperty("SelectionNamespaces",...).

    The error specified that the parentnode (logGroup) is with a certain namespace and thus expecting "LogEntries" to have the same namespace.

    Any idea anyone? :(


    --------------------------------------------------------------------------
    //write get the XML of repeating node into a string
    var sRepeatingXml = "<LogEntries><name>NameValue<name><age>Agevalue</age><LogEntries>";

    //create a Dom for the XMLNode
    var oXml = XDocument.CreateDOM();

    oXml.async = false;
    oXml.loadXML(sRepeatingXml);
    oXml.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-03-04T02:16:49'");

    //Get the Parent of the repeating table
    var parentofRepeatingNode = XDocument.DOM.selectSingleNode("/my:myFields/my:logGroup");

    //append the repeating XML Element to the Parent node
    parentofRepeatingNode.appendChild(oXml.documentElement);
    --------------------------------------------------------------------------
  • 04-15-2005 01:09 AM In reply to

    Re: Inserting into Repeating Table Programmatically

    It looks like your XML has a prefix of "my" so you need to add "my" as a prefix to your XML string also. And one more thing you need to take care of is "CASE of the letters in the XML nodes and starting and end tags". Try the following xml string it might help you

    var sRepeatingXml = "<my:LogEntries xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-03-04T02:16:49'><my:name>NameValue</my:name><my:age>Agevalue</my:age><my:LogEntries>";

    Agni
    InfopathDev India
  • 04-16-2005 09:59 PM In reply to

    Re: Inserting into Repeating Table Programmatically

    hihihi

    yeah it works now.
    super duper thanks for this...saved me a lot of trouble, really! :D
  • 03-10-2006 01:59 AM In reply to

    Re: Inserting into Repeating Table Programmatically

    Hello Agni,

    Here is my Code:

    [InfoPathEventHandler(MatchPath="btnShow", EventType=InfoPathEventType.OnClick)]
    public void btnShow_OnClick(DocActionEvent e)
    {
    try
    {
    string RepeatingXML = "<my:XMLTable xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-10T08-06-14'><my:Username>Vasanth</my:Username><my:Age>23</my:Age><my:City>Bangalore</my:City></my:XMLTable>";

    IXMLDOMDocument oXML = thisXDocument.CreateDOM();
    oXML.async = false;
    oXML.loadXML(RepeatingXML);

    IXMLDOMNode ParentTable = thisXDocument.DOM.selectSingleNode("my:myFields/my:XMLView/my:XMLTable");

    ParentTable.appendChild(oXML.documentElement);
    }
    catch(Exception ex)
    {
    ErrorMsg.text = ex.Message;
    }
    }

    But its not working porperly...

    Error is:

    Element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-10T08-06-14}XMLTable' is unexpected according to content model of parent element 'http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-03-10T08-06-14}XMLTable'.

    Can you please help me!

    Regards,
    vasanth.
  • 03-10-2006 02:04 AM In reply to

    Re: Inserting into Repeating Table Programmatically

    No Problem I got it.

    I have to remove one extra group name thats all.

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