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!

Knowledge Chat Bot (No Code)

Recently my customers was looking for a solution where on-field guys can search for answers related to their tasks and it was a perfect scen...