Sensitivity Labels in the Microsoft Information Protection service allow you to classify and protect the data of your organization. In addition to applying labels to documents and emails, you can also use sensitivity labels with Microsoft Teams, Microsoft 365 Groups and SharePoint sites. Classification is a great feature, it also allows to add functionality restrictions associated to a specific label: disallowing external users, forcing a Teams team to be private, etc.
One of my customers decided to tag their documents and sites/groups/teams, but wanted the label to show up in their search-based dashboards built using the Modern Search web parts.
It wasn't easy to find this information, digging through the out of the box search schema of SharePoint. Eventually I reached out to the product group who kindly provided me with some answers.
Sensitivity Label id
The GUID of a sensitivity label that is attached to the object gets crawled by SharePoint search, so that is a good start. The method and results are different depending on if the object is a document or a container (site/group/team):
Documents
For documents, the sensitivity label id is stored in the InformationProtectionLabelId managed property. It can be used for Query, Retrieve and Refine.
Sites/Groups/Teams
For container objects, there isn't a managed property in the search index but just a crawled property named ows_IpLabelId. The solution is to create your own managed property for this crawled property, and make sure you enable it for Query, Retrieve and Refine.
Sensitivity Label text
I asked for the text value of a Sensitivity Label, but was disappointed by the response. At least for now, this is not crawled anywhere.
There was a good technical explanation about why the label is not in the search index, but if SharePoint managed metadata labels can work around that for 10 years already surely it must be possible for this too?
Without the actual text label, my search dashboard wouldn't be very user friendly. In my next post, I will explore the many options to get the text label of a Sensitivity Label through API's to workaround this issue.