Top Menu

Friday, May 29, 2009

SharePoint: CAML Query - AND

I was ANDing three SharePoint fields in CAML Query based on the regular logic (place And between all three fields) and was getting errors with absolutely no clue that what possibaly could be wrong.
Here is the right way...thanks to Google:


Target: field1 && field2 && field3
Correct CAML:

<where>
  <and>
    <and>
      <eq>
        <fieldref name="field1">
        <value type="Text">val1</value>
      </fieldref></eq>
      <eq>
        <fieldref name="field2">
        <value type="Text">val2</value>
      </fieldref></eq>
    </and>
    <eq>
      <fieldref name="field3">
      <value type="Text">val3</value>
    </fieldref>
   </eq>
  </and>
</where>

Happy CAMLing!

No comments:

Post a Comment

Official SharePoint Documentation

I have recently contributed to the official SharePoint documentation for developement. Check it out here: https://docs.microsoft.com/en-us...