I'm trying to build a CAML query for a managed metadata column. I'm following the guidelines provided here by Microsoft. Essentially they say to query for the term's Wssid. No problem, I can do that.

Unfortunately the query is not working, and I'm getting back all of the list items, not just the one I'm looking for.

I've stepped through my code and seen the Wssid returned from TaxonomyField.GetWssIdsOfTerm() for a particular term, and then Powershelled in to the list and checked the item that has that term and verified the Wssid is the same. So I at least know that that part of the query is not wrong.

So, I cracked open CAML Designer to see if I could figure out what was going wrong, and when I selected the list in question, the field I'm trying to query against is not in the list of fields to choose from! I checked a couple other lists where that field is used, and the same is true in those lists -- the field I'm looking for is not available to be chosen in CAML Designer. I do see other custom managed metadata fields though, so I know it's not the fact that the field is a taxonomy field.

So... what's the property that's preventing my field from being available to CAML queries?


Did some more research... I found this interesting question/answer on MSDN. Apparently you can see the CAML queries SharePoint itself generates by creating a view on the list you are trying to query, and setting up a filter for that view that generally matches what you want your query to do. Then save your list as a template, download the .stp file, change it to a .cab file, and look at the manifest.xml. In the "Views" section of the manifest, you will see your view, and the CAML query it uses.

The funny thing is, even though the field is a managed metadata field, the query that SharePoint generates for a view is:

    <FieldRef Name='MyFieldInternalName' />
    <Value Type='Text'>Some Value</Value>

And, of course, even though that somehow works when SharePoint does it, it did not work for me when I tried it.

Any ideas would be appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.