5

I have this CAML query

var query = new SPQuery{
     Query = string.Format(@"<Where>
          <Or>
                <Or>
                     <Or>
                          <Or>
                                <Contains>
                                     <FieldRef Name='{7}' />
                                     <Value Type='Text'>{3}</Value>
                                </Contains>
                          </Or>
                          <Contains>
                                <FieldRef Name='{6}' />
                                <Value Type='Text'>{2}</Value>
                          </Contains>
                     </Or
                     <Contains>
                          <FieldRef Name='{5}' />
                          <Value Type='Text'>{1}</Value>
                     </Contains>
                </Or>
                <Contains>
                     <FieldRef Name='{4}' />
                     <Value Type='Text'>{0}</Value>
                </Contains>
          </Or>
     </Where>", "title", "adress", "zipcode", "city", "searchTitle", "searchAdress", "searchZipcode", "searchCity")
};

Every time it's ran and I try to use List.GetItems(query); it throws this error:

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

BUT! If I remove all the <Or> tags it works and doesn't throw that error, but I need the <Or> tags to make sure it get all hits.

I've made sure all the fieldrefs matches the internal names of the columns 100%.

Kit Menke
  • 4,193
  • 6
  • 32
  • 40

4 Answers4

7

Typically this error means that one of the columns you are querying is incorrect. Remember, you must use the Internal column name (an easy way to find the internal column name).

In this specific case, as @JamesLove points out, you have two columns that are misspelled: adress and searchAdress (also, title does not have the correct case).

In addition, you had an extra pair of <Or></Or> nodes.

var query = new SPQuery{
   Query = string.Format(@"<Where>
      <Or>
         <Or>
            <Or>
               <Contains>
                  <FieldRef Name='{7}' />
                  <Value Type='Text'>{3}</Value>
               </Contains>
               <Contains>
                     <FieldRef Name='{6}' />
                     <Value Type='Text'>{2}</Value>
               </Contains>
            </Or
            <Contains>
               <FieldRef Name='{5}' />
               <Value Type='Text'>{1}</Value>
            </Contains>
         </Or>
         <Contains>
            <FieldRef Name='{4}' />
            <Value Type='Text'>{0}</Value>
         </Contains>
      </Or>
   </Where>", 
   "Title", "address", "zipcode", "city", "searchTitle", "searchAddress", "searchZipcode", "searchCity")
};
Kit Menke
  • 4,193
  • 6
  • 32
  • 40
1

You specified incorrect column name. Try to use U2U CAML Query Builder. It will build the query based on the internal column names. Is also works with SP2010 even it doesn't specified exactly.

AlexSSE
  • 703
  • 2
  • 6
  • 17
1

Well, this can also happen when your query is actually not syntactically correct. Extra OR, AND also result into the same error

0

Just to throw a complete alternative into the mix: This error also crops up if you have a column based on a broken or uninstalled Custom Field Type.

A quick look at the List Settings page will show you if this is the case; the troublesome columns will be marked as invalid (with the option to delete them).

Stu Pegg
  • 4,623
  • 7
  • 48
  • 91