I guess alot of you that if you rename the Title field in a SharePoint list, the internal name is still “Title” (only the viewable name is actually changed). I had such a scenario where another developer had renamed the Title field to E-mail because there was really no need for having a title field in the list.
By itself this posed no problem, but when you work intensive with CAML problems quickly add up. When writing CAML queries in SharePoint you query on the internal name of the field. This didn’t pose as a problem for me, I just made a comment in the code so my fellow developers could see why I’d written “Title” in my query when the “E-mail” was what I needed. After I then ran my code nothing happend. SharePoint just returns “0 found posts” if anything is wrong with the CAML query making it hard to really see where the error is.
Somewhat confused by this, I downloaded the Stramit SharePoint Caml Viewer. Great application. When looking at the data for the entire list, I could see another field called “LinkTitle”. When I used this in my query it magically worked.
While I found a solution, I was really too far out in the internal fields of SharePoint, so I deleted the list and created a new one WITH THE TITLE FIELD . I’m not sure if this oddity was caused by all the renaming but the lesson learned (at least for me) was: Don’t mess with the title field…
If you’re still reading, a quick tip for working with lookup fields in CAML. A normal caml query with lookup looks like:
<Where><Eq><FieldRef Name=”Category” /><Value Type=”Lookup”>My category</Value></Eq></Where>
Nothing fancy here, but something that I’ve only found on a few blogs out there is how to do the lookup with the item id. Here’s how:
<Where><Eq><FieldRef Name=”Category” LookupId=”TRUE” /><Value Type=”Lookup”>234</Value></Eq></Where>