A Practical Guide to SharePoint 2013

A Practical Guide to SharePoint 2013
A Practical Guide to SharePoint 2013 - Book by Saifullah Shafiq

Sunday, June 10, 2007

What is the datatype of the Yes/No field?

Value type has to be provided when writing a query for the SPQuery object. How do you access a Yes/No field or let's put it in another way! What is the data type of the Yes/No field in SharePoint? The data type is "Boolean" and the value has to be provided as 1 or 0. Providing a value of Yes or No or True or False will not work. Ok, sometimes the query fails even if you provided the value as 1 or 0. You get a strange error. Following is the error message:

"One or more field types are not installed properly. Go to the list settings page to delete these fields"

To fix this error, you will have to use the internal name of the field in the spquery. Yes, internal names can be different from the names displayed in the site. For example, internal name for the field "My Field" can be "My_x0020_Field".

Here is the sample code:

SPQuery query = new SPQuery();
query.Query = "<Where><Eq>FieldRef Name='My_x0020_Field'></FieldRef><Value Type='Boolean'>1</Value></Eq></Where>";

This will search for records where "My Field" has the value of 1 (Yes).

Easiest way to find the internal name of the field is to open the "New" form in browser and then view it's source. Right-click any where in the "New" form to open the context menu and select "View Source". You will find the fields along with their internal names near the end of the source file.


No comments:

Post a Comment