Beware Long Fields In CAML Queries – Must Use Truncated Name

Well, this is a new one for me. Tonight while making an application page I came across a frustrating thing. So here’s the scenario. I have list 1 called “TheParentList”, and no that’s not the real name. I have a second list called “theChildList”, again, not the real name.

My lookup column internal name, as a site column, is “Link_x0200_to_x0200_TheParentList_x0200_List_instructions

My CAML query is pretty straight forward and looks like this:

<Where><Eq><FieldRef Name=’Link_x0200_to_x0200_TheParentList_x0200_List_instructions’ LookupId=’TRUE’><Value Type=”Lookup’>4</Value></Eq></Where>

Further down the page I am displaying this field. So, theitems[“Link_x0200_to_x0200_TheParentList_x0200_List_instructions”].ToString();

Can you guess what happens? If I comment out my query, the page loads and the field is displayed just fine. If I try to use my query I get the “One or more field types are not installed properly”. So, after beating my head for hours I thought, well, when I click on the column from within the LIST and NOT from within the site column, I get a different name. I get¬†Link_x0200_to_x0200_TheParentList_x0200_Li.

Notice the truncated name?? Well, if you try to use that truncated name in your call to display the field, theitems[“”].ToSTring(), it will fail because that’s not really the internal name.

However, apparently, when using a CAML query, the internal name of the field is actually the truncated value and NOT the full value. Crazy.

This will only happen with really long field names, which is why I suspect there isn’t much out there on it.

Hope this helps someone one day!

 

Comments are closed.