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.

No comments:

Post a Comment