Search code examples
vb.netweb-servicessharepointsharepoint-2007

SharePoint: GetListItems soapserverException being thrown because of Query


I am using designing a Windows Form application using VB.net. I trying to have the application return the number of rows in a specific SharePoint List. Everything works perfectly when I I remove the ndQuery.InnerXml code; however, I want to filter the list before I get the count. The two columns I want to filter are "Assigned Employee" and "status." I looked at many different posts here on Stack(SharePoint SoapServerException calling GetListItems web service), but my Exception is relating to the Query. The detail of the soapserverException is: "One or more field types are not installed properly. Go to the list settings page to delete these fields: 0x81020014."

I tried going to the relationship page, but I could not browse to it:

(url)/Relationships%20List/allitems.aspx

Can any one see a problem with the Query code?

Imports System
Imports System.IO
Imports System.Net
Imports System.Xml
Imports <xmlns="rs">
Public Class Form1

Dim i As Integer

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim listService As New getListItems.Lists
    listService.Credentials = CredentialCache.DefaultCredentials
    listService.Url = "http://(servername)/_vti_bin/Lists.asmx"
    Dim xmlDoc = New System.Xml.XmlDocument()

    Dim ndQuery As XmlNode =
    xmlDoc.CreateNode(XmlNodeType.Element, "Query", "")
    Dim ndViewFields As XmlNode =
        xmlDoc.CreateNode(XmlNodeType.Element, "ViewFields", "")
    Dim ndQueryOptions As XmlNode =
        xmlDoc.CreateNode(XmlNodeType.Element, "QueryOptions", "")

    ndQueryOptions.InnerXml =
        "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>"
    ndViewFields.InnerXml = "<FieldRef Name='Assigned Employee'/><FieldRef Name='Status'/>"
    ndQuery.InnerXml = "<Where><And><Contains><FieldRef Name ='Assigned Employee'/><Value Type='Text'>Engineer</Value></Contains><Contains><FieldRef Name='Status'/><Value Type='Text'>New</Value></Contains></And></Where>"

    Try

        Dim ndListItems As XmlNode =
                listService.GetListItems("Requests", Nothing, ndQuery, _
                ndViewFields, Nothing, ndQueryOptions, Nothing)

        Dim n1 As XmlNode = ndListItems.Item("rs:data")
        Dim a As String = n1.Attributes("ItemCount").InnerText

        'Attempted For each loop, but not needed:
        'Dim listItemCount As String
        'Dim innerXML = New System.Xml.XmlDocument
        'innerXML.LoadXml(ndListItems.InnerXml)
        'Dim rows As XmlNodeList = innerXML.GetElementsByTagName("rs:data")

        'For Each (XmlNode Attribute In rows)
        'Next


        Label1.Text = a

    Catch ex As System.Web.Services.Protocols.SoapException

        Label1.Text = ("Message:" + ControlChars.Lf + ex.Message +
            ControlChars.Lf +
        "Detail:" + ControlChars.Lf + ex.Detail.InnerText +
            ControlChars.Lf +
        "StackTrace:" + ControlChars.Lf + ex.StackTrace)

    End Try
End Sub
End Class

Solution

  • I discovered the problem when breaking apart the query statement into two parts:

    'ndQuery.InnerXml = "<Where><Eq><FieldRef Name ='Assigned_x0020_Employee'/><Value Type='Text'>Engineer</Value></Eq></Where>"
    'ndQuery.InnerXml = "<Where><Eq><FieldRef Name ='Status'/><Value Type='Text'>New</Value></Eq></Where>"
    

    I figured out that although one of the Columns in the SP list was named "Assigned Employee," the actual FieldRef Name was just employee. When I modified the code to include that, the error went away. I was spending all my time changing the Value Type, instead of looking at the FieldRef Name

    Final Conclusion: The "one or more field types are not installed properly" error not only gets returned if the "Value Type" is incorrect, but also when the "FieldRef Name" contains the wrong label.

    Final working code line:

    ndQuery.InnerXml = "<Where><And><Eq><FieldRef Name ='Employee'/><Value Type='Text'>Engineer</Value></Eq><Eq><FieldRef Name='Request_x0020_Status'/><Value Type ='Text'>New</Value></Eq></And></Where>"