Solved

How do I solve a SOAP error when submitting an InfoPath 2007 form with repeating tables to a SharePoint list:

Posted on 2010-09-07
5
2,741 Views
Last Modified: 2012-05-10
The SOAP response indicates that an error occurred on the server:

Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.
<detail><errorstring xmlns="http://schemas.microsoft.com/sharepoint/soap/">Value does not fall within the expected range.</errorstring></detail>

I have followed the instructions on this page: http://www.bizsupportonline.net/infopath2007/how-to-submit-items-rows-repeating-table-infopath-sharepoint-list.htm  and can't get past the error.  I've tried the GUID with and without braces.  I've tried adding his code to the button click event and replacing the default.  It fails at this line: DataConnections("CustomListItemsSubmit").Execute() (last line in the btnSubmitMinutes_Clicked sub.  The code is attached.  

I'm looking forward to the help anyone can give me that will stop my wheels from spinning; thanks in advance.
Imports Microsoft.Office.InfoPath
Imports System
Imports System.Windows.Forms
Imports System.Xml
Imports System.Xml.XPath
Imports mshtml


Namespace GFMCMinutesForm5
    Public Class FormCode
        ' Member variables are not supported in browser-enabled forms.
        ' Instead, write and read these values from the FormState
        ' dictionary using code such as the following:
        '
        ' Private Property _memberVariable() As Object
        '     Get
        '         _memberVariable = FormState("_memberVariable")
        '     End Get
        '     Set
        '         FormState("_memberVariable") = value
        '     End Set
        ' End Property

        ' NOTE: The following procedure is required by Microsoft Office InfoPath.
        ' It can be modified using Microsoft Office InfoPath.
        Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup
            AddHandler DirectCast(EventManager.ControlEvents("btnSubmitMinutes"), ButtonEvent).Clicked, AddressOf btnSubmitMinutes_Clicked
        End Sub

       

        Public Sub btnSubmitMinutes_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
            ' Delete all Method nodes from the CAML Batch XML
            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

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

                ' Increment the counter
                counter = counter + 1
            End While

            ' Submit the rows to the Lists web service to update the custom list
            DataConnections("CustomListItemsSubmit").Execute()
        End Sub
        Public Sub AddMethodNode(ByVal id As Integer, ByVal title 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("</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
    End Class
End Namespace

Open in new window

0
Comment
Question by:nsyyoung
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:arduk
ID: 33622831
Have you had a look at the actual batch xml that is being submitted? It may give you (or us) some clue as to what is incorrect.

Also, whenever I have used the lists.asmx web service (not through infopath admittedly), I have always used the list name, rather than the guid - you may be able to try that.

If you can't get it to work submitting it this way, you could always add a reference to the lists.asmx webservice directly, and then build the xml, and call the webservice directly through code. May be a little more work, but at least you would have full control over everything...

Hope this helps...
0
 
LVL 8

Author Comment

by:nsyyoung
ID: 33623056
Oh, boy.  Where do I find the actual batch file? I will try it with the listname instead and report back.
And how would I go about following your second suggestion?  This is all fairly new for me.
0
 
LVL 7

Expert Comment

by:arduk
ID: 33623364
I have just tried this code (I used the c# version) with the list name rather than the guid, and it seems to work - the items are actually added to the list.
I did get an error indicating that it had failed (NOT a SOAP error), but adding the line below after executing the submit of the data connection seems to have resolved that (remember this is in c# - so syntax may be slightly different for you in VB?)
e.CancelableArgs.Cancel = false
to indicate that it has worked...

Considering that I have been through this and it works exactly as is, I would suggest going back over the steps in the article, and ensuring that your datasources are setup correctly - particularly check that the listName parameter is mapped correctly on the "CustomListItemsSubmit" datasource.
If your datasources are correct, I would then try using the list name, rather than the guid (you can use either, but it could be an issue with the guid being incorrect, using list name will get around that)


As for finding out the actual values in the xml batch:
in your code, the following lines are adding each of the methods to the xml batch code (below is the correct VB code I believe):
            Dim secDSNav As XPathNavigator = DataSources("CustomListCAML").CreateNavigator()
            Dim batchNav As XPathNavigator = secDSNav.SelectSingleNode("/Batch", NamespaceManager)
            batchNav.AppendChild(methodXml.DocumentElement.CreateNavigator())

so what you are actually ending up with here is an xml node "Batch" that has the details of the items to be added to the list.

To get the actual content of that node, add the following lines of code before the submit:
            secDSNav = DataSources("CustomListCAML").CreateNavigator()
            Dim batchNav As XPathNavigator = secDSNav.SelectSingleNode("/Batch", NamespaceManager)
dim batchContents as string = batchNav.OuterXml;

Put a break point after the code above, and then examine the contents of "batchContents"

When I did this, having entered 3 rows in the repeating table with the values "test item 1", "test item 2", "test item 3", I get the following as the value of "batchContents"
"<Batch>\r\n\r\n<Method ID=\"1\" Cmd=\"New\"><Field Name=\"Title\">test item 1</Field></Method><Method ID=\"2\" Cmd=\"New\"><Field Name=\"Title\">test item 2</Field></Method><Method ID=\"3\" Cmd=\"New\"><Field Name=\"Title\">test item 3</Field></Method></Batch>"

0
 
LVL 8

Author Comment

by:nsyyoung
ID: 33663298
Thanks, I'll try that and see how it goes.
0
 
LVL 8

Accepted Solution

by:
nsyyoung earned 0 total points
ID: 33757161
I figured it out.  I have 2 fields that are lookup fields, both string datatypes.  The form didn't want to submit its own string to the lookup field, even though the string given was already in the lookup list.
So I deleted the lookup columns and recreated them as single line of text boxes and now it works fine.
thanks for the suggestions.
0

Featured Post

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question