Archive for March 31, 2015

Alternate to CAML Or

In is a lesser known CAML operator that I’d like to bring to more peoples attention. When writing CAML and you want to restrict the results by a multi value field equaling two or more values, you’d write something like:

<where>
<or>
  </or><or>
    <eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Scotland</value></values>
    </eq><eq>
    </eq><eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">England</value></values>
    </eq><eq>
  </eq></or>
  <or>
    <eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Wales</value></values>
    </eq><eq>
    </eq><eq>
      <fieldref Name="Country"></fieldref><values><value Type="LookupMulti">Ireland</value></values>
    </eq><eq>
  </eq></or>
 
</where>

This will return any item that has the value Scotland, England, Wales or Ireland in the Country field. As the number of values you want to match against grows, imagine the state of the CAML query!
Read more

Follow

Get every new post delivered to your Inbox

Join other followers: