CAML query with more than multiple AND/OR generates SPException “One or more field types are not installed properly. Go to the list settings page to delete these fields.”

sharepoint.stackexchange https://sharepoint.stackexchange.com/questions/10222

  •  16-10-2019
  •  | 
  •  

Question

I need to build a CAML query at runtime based on user input. The CAML query could be as simple as

<Where>
  <Eq>
    <FieldRef Name="Status" />
    <Value Type="Text">Awaiting Completion</Value>
  </Eq>
</Where>

or might include multiple AND and OR like

<Where>
  <Or>
    <Or>
      <Eq>
        <FieldRef Name="Status" />
        <Value Type="Text">Awaiting Completion</Value>
      </Eq>
      <Eq>
        <FieldRef Name="Status" />
        <Value Type="Text">Ongoing</Value>
      </Eq>
    </Or>
    <Eq>
      <FieldRef Name="status" />
      <Value Type="Text">Postponed</Value>
    </Eq>
  </Or>
</Where>

The problem is that as soon as I add a third Status to check as in the query above it generates an SPException

"One or more field types are not installed properly. Go to the list settings page to delete these fields"

A quick code snippet to reproduce the problem:

   using (SPSite spSite = new SPSite("http://sp2010"))
            {
                using (SPWeb spWeb = spSite.OpenWeb("/test"))
                {
                    SPQuery spQuery = new SPQuery();
                    spQuery.Query = "<Where><Or><Or><Eq><FieldRef Name=\"Status\" /><Value Type=\"Text\">Awaiting Completion</Value></Eq><Eq><FieldRef Name=\"Status\" /><Value Type=\"Text\">Ongoing</Value></Eq></Or><Eq><FieldRef Name=\"status\" /><Value Type=\"Text\">Postponed</Value></Eq></Or></Where>";                    
                    SPListItemCollection spListItemCollection = spWeb.Lists["Actions"].GetItems(spQuery);
                    foreach(SPListItem spListItem in spListItemCollection)
                    {
                        Console.WriteLine(spListItem.Title);
                    }
                }
            }

            Console.ReadKey();

Any ideas?

Was it helpful?

Solution

Ok, I'm turning my comment into answer.
Onse in a while we all are making a typos - to solve your problem you should use "Status" instead of "status" in 3rd <Eq>.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top