Most Read Latest News Blog Resources

Share Pointers: Yes/No fields aren’t your friends




February 4, 2009 — 
Not too long ago, I was working with a client who reminded me of one of my least favorite nuances about SharePoint: Yes/No site columns.

It sounds pretty simple, right? Perhaps you need to make a list to store information about projects. You would create a new list and add the site columns to store the information for the project.  Imagine that one of the requirements is to create a field to answer the question, “Is this an open project?” You review your options and decide that, since this is a “yes” or “no” type question, clearly the Yes/No field type would be the best option for the job. Look at its name, it is so obvious this is the best option, right? Technically it would "work" just fine. But there's an issue.

Before we get ahead of ourselves, you may have used this field type before and be thinking to yourself, “It works just fine. I added the field and it shows up in my view as No." You are correct, you probably selected No in your list item, and when it saved, it will show up as No in your view.

But what actually happened is that behind the scenes, that No has been stored as a 0. If you had said Yes, it would have been stored as a 1. SharePoint knows how to interpret this and will display these 1s and 0s as Yes and No for your convenience.

This can cause confusion if you try to run searches or use things like the Content Query Web Part. For example, a user might create a CQWP that only shows projects that are listed as Open. The user would add the CQWP, set the filter criteria to look at the Yes/No field and set the filter value to Yes. However, no projects would show up in the CQWP, because in order to get the expected results, you would need to specify the filter value as 1, not Yes.

There is an easy answer to this common issue. To avoid any potential confusion, I strongly recommend against using Yes/No fields and instead suggest people use a Choice field, then specify the values as Yes and No. This behaves exactly like you'd expect. The values that are stored in the database are actually Yes and No. There’s no need to mess with 1s and 0s.

Let’s go back to the original project list that was described at the beginning. In this case, to address your requirement of creating a site column to determine whether a project was open or not, you decide to create a Choice field and give it values of Yes and No.  Now when any of your users tries to perform the obvious task of searching or filtering on that field, they will get expected results without needing to deal with this little nuance.

John Ross is a Senior Consultant with SharePoint911. Check out his new book, “MOSS Explained: An Information Worker's Deep Dive into Microsoft Office SharePoint Server 2007,” which shows users how to solve many common business problems without writing any code.


Related Search Term(s): SharePoint


Share this link: http://www.sdtimes.com/link/33246
 

Comments

02/19/2009 08:37:12 AM EST

As a database programmer I would disagree. In fact, I would say that the CQWP is not performing as it should and thus should be changed. In my humble opinion, data fields should reflect, as closely as possible, the datatype stored within. You wouldn't use a varchar field to store timestamps, and you wouldn't use a decimal field to store integers. Why use an xxchar field to store bit values? I would humbly accept someone telling me that I'm wrong. Brian

United StatesBrian


Add comment


Name*
Email*  
Country     


  • Comment
  • Preview
Loading



 
 
 
 
News on Monday
more>>
SharePoint Tech Report
more>>


   

 
 
Download Current Issue
ISSUE 3/15/2010 PDF

Need Back Issues?
DOWNLOAD HERE

Receive the print Edition?


 
blogs tab
Google Code turns 5
Google Code Turns 5, and adds a Paxos Algorithm to make the system more stable and reliable.
03/17/2010 11:16 AM EST

Test your Visual Studio 2010 know-how
Microsoft is offering free beta certification exams for Visual Studio 2010.
03/17/2010 11:08 AM EST

Microsoft lifts the hood on IE9
Microsoft is previewing IE9.
03/16/2010 01:10 PM EST

 

Events calendar tab
3/22/2010 to 3/25/2010
Santa Clara, Calif.
The Eclipse Foundation

4/12/2010 to 4/14/2010
Las Vegas
Penton Media

4/12/2010 to 4/15/2010
Santa Clara, Calif.
O'Reilly Media

4/19/2010
New York City
Flagg Management

4/25/2010 to 4/28/2010
Overland Park, Kans.
IIUG