Showing posts with label caml. Show all posts
Showing posts with label caml. Show all posts

November 18, 2011

SharePoint: CAML filtering for Managed Metadata field that is empty

Problem:

How to write CAML filter that would show items where a specific Managed Metadata field is empty?

Solution:

You need to use IsNull.

<Query><Where><IsNull><FieldRef LookupId="TRUE" Name="ManagedMetadataColumnName" /></IsNull></Where></Query>

LookupId=”TRUE” is optional in this case. If you include it, you are actually comparing if ID of the metadata field value is NULL. If you leave it out, you are comparing if the actual text of the metadata field value is NULL. Either way, same result.

SharePoint: How to get lookup ID of a Managed Metadata Term without having to use GetWssIdOfTerm()

Problem:

In SharePoint Online (Office 365) and on-premise SharePoint, how do I get the lookup ID of a Managed Metadata Term without having to write code anad use GetWssIdOfTerm() method?

Solution:

Go to the hidden list at the root of your site collection, e.g., http://yoursite.com/lists/TaxonomyHiddenList and look at the ID field of the respective metadata item.

image

Further explanation on how to actually use that ID in a CAML query can be found here. It actually works in DFWP.