Add new blank row to repeating table using a button. - InfoPath Dev

InfoPath Dev

Use our Google Custom Search for best site search results.

Add new blank row to repeating table using a button.

Last post 03-25-2012 11:32 PM by Jo-Anne Alfafara. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 03-25-2012 12:38 AM

    Add new blank row to repeating table using a button.


    I have a browser-enabled form that I developed in InfoPath 2007.

    On the form I have set up a button that if pressed must force the user to enter a value in a new row of my repeating table (I'm basically asking a user to provide a reason why they are doing something). 

    This means that every time the button is pressed a new blank row must be automatically added via code and not allow the user to save the changes unless the reason is provided.

    My repeating group CallHoldDetails consists of 4 fields:

    /my:myFields/my:CallDetails/my:CallHold/my:CallHoldDetails/my:CallHoldReason  (Text)

    /my:myFields/my:CallDetails/my:CallHold/my:CallHoldDetails/my:CallHoldStartDate (Date)

    /my:myFields/my:CallDetails/my:CallHold/my:CallHoldDetails/my:CallHoldEndDate (Date)

    /my:myFields/my:CallDetails/my:CallHold/my:CallHoldDetails/my:CallDaysOnHold  (Integer)

    I have come up with the following code but it doesn't work:

    XPathNavigator xCheck = MainDataSource.CreateNavigator();

    XPathNodeIterator RepTable = xCheck.Select("/my:myFields/my:CallDetails", NamespaceManager); while (RepTable.MoveNext()){      string LastHoldReason = RepTable.Current.SelectSingleNode("/my:myFields/my:CallDetails/my:CallHold[last()]/my:CallHoldDetails", NamespaceManager).Value;       if (LastHoldReason != "")                    {                        

    string myNamespace = NamespaceManager.LookupNamespace("my");

    using (XmlWriter writer = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:CallDetails/my:CallHold", NamespaceManager).AppendChild())

    {                            writer.WriteStartElement("CallHoldDetails", myNamespace); writer.WriteElementString("CallHoldReason", myNamespace, ""); writer.WriteElementString("CallHoldStartDate", myNamespace, ""); writer.WriteElementString("CallHoldEndDate", myNamespace, ""); writer.WriteElementString("CallDaysOnHold", myNamespace, ""); writer.WriteEndElement(); writer.Close();                        }                        }                }

    The issue is that when the very first time the button is pressed there are no values, so it shouldn't add anything, but it does add an new row. At the same time even if I put in values CallHoldDetails it throws an error when I try to submit the form - it may be to do with the data types of the new row not matching the field types.

    Any help would be much appreciated.

  • 03-25-2012 11:32 PM In reply to

    Re: Add new blank row to repeating table using a button.


    Jimmy posted a sample code snippet here:

    Hope that helps.

    Jo-Anne Alfafara
    Qdabra® Software/
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™
Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.