[TIP – Sharepoint] – CAML Query – Filtering Boolean fields

A few days ago I needed to build a CAML query that return all the items which have changed since the last execution. I have a Yes/No (boolean) field called “HasChanged” that when the item is changed turns to “True”.

The query would be something like this:

<Query>
   <Where>
       <Eq>
         <FieldRef Name="HasChanged" />
         <Value Type="Boolean">true</Value>
      </Eq>
   </Where>
</Query>


The truth is that this query will not work as you might think. For Sharepoint, Yes/No fields are represented by 1 and 0. As so, the query has to be like:

Upgrade your computer with an SSD


<Query>
   <Where>
       <Eq>
         <FieldRef Name="HasChanged" />
         <Value Type="Integer">1</Value>
      </Eq>
   </Where>
</Query>

After loosing a couple of hours on this, I hope to be useful ;)

2 thoughts on “[TIP – Sharepoint] – CAML Query – Filtering Boolean fields”

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA Image

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>