Error submitting to SharePoint List when ampersand included in field - InfoPath Dev
in

InfoPath Dev

Error submitting to SharePoint List when ampersand included in field

Last post 10-28-2013 08:21 AM by Hilary Stoupa. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 10-24-2013 01:13 PM

    Error submitting to SharePoint List when ampersand included in field

    I have a IP form with several questions for users answer. The fields are then submitted to a SharePoint list at which point a workflow runs and a word document is generated. Its really cool, and works great...most of the time. I started noticing the following error pop up from time to time, which seemed to be completely random:

    An error occurred while parsing EntityName. 
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.ParseEntityName()
       at System.Xml.XmlTextReaderImpl.ParseEntityReference()
       at System.Xml.XmlTextReaderImpl.Read()
       at System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace)
       at System.Xml.XmlLoader.LoadDocSequence(XmlDocument parentDoc)
       at System.Xml.XmlDocument.Load(XmlReader reader)
       at System.Xml.XmlDocument.LoadXml(String xml)
       at Form1.FormCode.AddMethodNode(Int32 id, String title, String customername, String customernumber, String purchaseamount)
       at Form1.FormCode.CTRL15_5(Object sender, ClickedEventArgs e)
       at Microsoft.Office.InfoPath.Internal.ButtonEventHost.OnButtonClick(DocActionEvent pEvent)
       at Microsoft.Office.Interop.InfoPath.SemiTrust._ButtonEventSink_SinkHelper.OnClick(DocActionEvent pEvent)

    It took a while, but I finally figured out what was causing the problem. There is a particular multi-line field where users are required to enter multiple paragraphs. If the user enters an ampersand anywhere in their text, the above error is thrown on submit.

    I've tried everything I can think of to fix this.

     I've tried using the translate function: translate(field,"&","and")  ---result is no error but that just returns an "a"

    I've tried concatenating < before and > after the field: concat("<",field,">") -----still get the error

    I've tried concatenating " before and " after the field: concat(""",field,""")-----Infopath doesn't like the function

    I've tried creating a textbox to hold the quotation and then concatenating: concat(quotefield,field,quotefield)-----still get the error

    The only thing I haven't done is translating it to something like % and then running an AutoOpen macro on the document to replace % with &....that just seems like a waste.

     Any suggestioins?

  • 10-24-2013 06:08 PM In reply to

    Re: Error submitting to SharePoint List when ampersand included in field

     Have you tried looking at the form code and making your changes there? Because this seems like an issue with the custom code.... you could run it in debug, see what's going awry?

    Hilary Stoupa

  • 10-25-2013 06:08 AM In reply to

    Re: Error submitting to SharePoint List when ampersand included in field

    Thanks for the quick reply Mrs. Stoupa,

    I ran the debugger and the follwoing error was was thrown when I put an ampersand in the field:

     XmlException was unhandled by user code

    the following line of code was referenced:

    methodXml.LoadXml (sb.ToString())

    I'm not going to try and pretend to be a programmer, I got this code from google. So, if the code needs to be adjusted to handle ampersands, that is well outside my current ability and understanding. However, I am a quick learner ;-)

    Thanks,

    Garrett

  • 10-28-2013 07:23 AM In reply to

    Re: Error submitting to SharePoint List when ampersand included in field

     Mind posting your code? I'm wondering what the variable "sb" is.

    Hilary Stoupa

  • 10-28-2013 07:43 AM In reply to

    Re: Error submitting to SharePoint List when ampersand included in field

    Here is the custom code. Note: this is a basic example that I used for testing, but the finished product is almost exactly the same, except there a many more fields.

            Public Sub AddMethodNode(ByVal id As Integer, ByVal title As String, ByVal customername As String, ByVal customernumber As String, ByVal purchaseamount As String)
                Dim sb As System.Text.StringBuilder = New System.Text.StringBuilder()
                sb.AppendFormat("<Method ID=""{0}"" Cmd=""New"">", id.ToString())
                sb.AppendFormat("<Field Name=""Title"">{0}</Field>", title)
                sb.AppendFormat("<Field Name=""customername"">{0}</Field>", customername)
                sb.AppendFormat("<Field Name=""customernumber"">{0}</Field>", customernumber)
                sb.AppendFormat("<Field Name=""purchaseamount"">{0}</Field>", purchaseamount)
                sb.AppendFormat("</Method>")

                Dim methodXml As XmlDocument = New XmlDocument()
                methodXml.LoadXml(sb.ToString())

                Dim secDSNav As XPathNavigator = DataSources("CustomListCAML").CreateNavigator()
                Dim batchNav As XPathNavigator = secDSNav.SelectSingleNode("/Batch", NamespaceManager)
                batchNav.AppendChild(methodXml.DocumentElement.CreateNavigator())
            End Sub

            Public Sub CTRL15_5(ByVal sender As Object, ByVal e As ClickedEventArgs)
                ' Write your code here.
                Dim secDSNav As XPathNavigator = DataSources("CustomListCAML").CreateNavigator()
                Dim iter As XPathNodeIterator = secDSNav.Select("/Batch/Method")
                Dim methodNodesCount As Integer = iter.Count

                Dim firstMethodNav As XPathNavigator = _
                   secDSNav.SelectSingleNode("/Batch/Method[1]", _
                   NamespaceManager)
                Dim lastMethodNav As XPathNavigator = _
                  secDSNav.SelectSingleNode("/Batch/Method[" & _
                  methodNodesCount.ToString() & "]", _
                  NamespaceManager)

                firstMethodNav.DeleteRange(lastMethodNav)

                ' Retrieve the rows of the repeating table
                Dim root As XPathNavigator = MainDataSource.CreateNavigator()
                Dim rows As XPathNodeIterator = root.Select( _
                  "/my:myFields/my:rows/my:row", NamespaceManager)

                ' Loop through the rows of the repeating table
                ' and construct the CAML Batch XML
                Dim counter As Integer = 1
                While rows.MoveNext()
                    ' Retrieve the title
                    Dim title As String = rows.Current.SelectSingleNode( _
                      "my:title", NamespaceManager).Value
                    Dim customername As String = rows.Current.SelectSingleNode( _
                      "my:customername", NamespaceManager).Value
                    Dim customernumber As String = rows.Current.SelectSingleNode( _
                      "my:customernumber", NamespaceManager).Value
                    Dim purchaseamount As String = rows.Current.SelectSingleNode( _
                      "my:purchaseamount", NamespaceManager).Value


                    ' Add an item to the CAML Batch XML
                    AddMethodNode(counter, title, customername, customernumber, purchaseamount)

                    ' Increment the counter
                    counter = counter + 1
                End While

                ' Submit the rows to the Lists web service to update the custom list
                DataConnections("CustomListItemsSubmit").Execute()
                'close the form
                Dim nav As XPathNavigator = MainDataSource.CreateNavigator()
                nav.SelectSingleNode("//my:field18", NamespaceManager).SetValue("URL")

            End Sub
        End Class
    End Namespace

    Thanks for you're help.

  • 10-28-2013 08:21 AM In reply to

    Re: Error submitting to SharePoint List when ampersand included in field

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