Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CAML query for boolean column is not working

Hi I have a SharePoint list to be queried for my Desktop App and I want to retrieve only the Active Members but when I queried I got only the users who aren't active. What is wrong with my CAML query?

camlQuery.ViewXml = "<<"View">><Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> " + true + "</Value></Eq></Where></Query></View>"";

I tried the following as well

camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> true</Value></Eq></Where></Query></View>";

and

camlQuery.ViewXml = "<Query><Where><Eq><FieldRef Name='Active'/><Value Type='Boolean'> true</Value></Eq></Where></Query>";

Please help as I'm new to CAML.

like image 522
Nirushan Ferdinand Chandran Avatar asked Jun 27 '12 05:06

Nirushan Ferdinand Chandran


People also ask

How does CAML Query work?

What is CAML query in SharePoint? CAML stands for Collaborative Application Markup Language and we use CAML to define queries against SharePoint list data or library data. And then we can use the SharePoint CAML query with CSOM or JavaScript or Server Object model. CAML is an XML-based query language.


3 Answers

Save yourself some grief and use a tool to help build up CAML queries such as U2U's Caml Query Builder.

You need to use 1 and 0 (not true and false) in the query, so

<Query><Where>
   <Eq><FieldRef Name="Active" /><Value Type="Boolean">1</Value></Eq>
</Where></Query>
like image 68
Ryan Avatar answered Oct 22 '22 09:10

Ryan


This Works for me

camlQuery.ViewXml = "<View>" + "<Query>" + "<Where>" + "<Eq>" +
"<FieldRef Name='Active'/>" + " <Value Type='Boolean'>" + "1" + "</Value>" +
"</Eq>" + "</Where>" + "</Query>" + "</View>";
like image 41
DevTard Avatar answered Oct 22 '22 10:10

DevTard


Use the value type Bool and it works with "true", "True" or "TRUE"

like image 1
user2470731 Avatar answered Oct 22 '22 09:10

user2470731