Categories: development, applications

CAML Or-Queries

Just another "RTFM"-Problem that I encountered the hard way:

<Or>-Queries in CAML look like this: ((((A or B) or C) or D) or E).
I accidentially assumed that they were (((A or B) or C or D) or E), but that just leads to Sharepoint 2007 giving the overly helpful "Cannot complete this action" Error message.

Example of a correct Query to have 5 OR-Directives:

<Where>
  <Or>
    <Or>
      <Or>
        <Or>
          <Eq><FieldRef Name='Author'/><Value Type='Text'>A</Value></Eq>
          <Eq><FieldRef Name='Author'/><Value Type='Text'>B</Value></Eq>
        </Or>
        <Eq><FieldRef Name='Author'/><Value Type='Text'>C</Value></Eq>
      </Or>
      <Eq><FieldRef Name='Author'/><Value Type='Text'>D</Value></Eq>
    </Or>
    <Eq><FieldRef Name='Author'/><Value Type='Text'>E</Value></Eq>
  </Or>
</Where>