Hi,
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.