Previous blog discuss about creation of view filter for Modern SharePoint site. This part we discuss how to create View filter based on Metadata field for Classic SharePoint site.
Classic SharePoint Site – How to Create View Filter
In my scenario I have a document library “Documents” which has several type of documents with the category. The category is the Metadata / Taxonomy field. The Category has EU as top level TermSet, below is the screenshot of the termset and terms.
Step – 1:
Create Document Library with the Taxonomy / Metadata field. In my case Category column with EU termset with all the terms. The document library has several folders and documents inside tagged with the metadata needed.
Step – 2:
Create a view to show all the documents without folder. Name the view as “O365 Files” the name can be any meaningful name which you can create. While creating the view make sure you select “Show all items without Folders” under Folders. In my case I want to see all documents uploaded to library without any folders. This view filter will be modified later by the PowerShell CSOM script.
Below is the view I created with the name O365 Files. This view will be changed using the PowerShell script to update the filtering metadata.
Step – 3
Identify the Metadata tag ID you want to filter. The metadata tag id is the hidden id which is created under the site collection to store the data. There will be a hidden list under site collection. Make sure you have atleast one document uploaded and tagged with the metadata you wanted to filter. The Metadata will have a unique Id in the hidden list. Navigate to https:///Lists/TaxonomyHiddenList/AllItems.aspx to get the list. I have created a new view for this list to see the Id column easily called ShowId. Below is the screenshot of the List with the Id column made visible. To filter the documents by O365 and all its children metadata note down all the Ids. In my case below are the ids
Step – 4:
Prepare to run the PowerShell CSOM script to update the View CAML. Download the CSOM dll from Nuget.org https://www.nuget.org/packages/Microsoft.SharePointOnline.CSOM/16.1.7414.1200 Use the Manual download link at the right side of the page. The downloaded file will be microsoft.sharepointonline.csom.16.1.7414.1200.nupkg based on the version you download. Unzip the file to the folder. You can change the file extension to .zip and unzip all files. Use the .net45 folder libraries for the CSOM PowerShell.
Step – 5:
Use the PowerShell below to update the View to filter by metadata. The LookUpId in the below code is the Hidden Metadata Id from the TaxonomyHiddenList.