Modern SharePoint Events WebPart Categories

black metal car seat aligned

So you want to manipulate the new Categories in the Events WebPart in SharePoint, here are few tips that might help you out!

First of all, you want to do your changes in the list itself, not on the site column. The site column itself won’t be helpful as you won’t find it unless you go to the content type first, and you’ll notice it’s in the Hidden category. So if you want to add your categories, you’ll need to do it on the list itself.

The Category column as it appears on the Event content type (as a site column)

What do you do it if you provision the list as part of a provisioning process aka PnP Provisioning 😉 ? Well, if you run Get-PnPSiteTemplate and try to get the list, you won’t find the categories as part of the exported template. So if we want to change the categories, we’d do it with PnP PowerShell. I’m using PnP.PowerShell module (using PowerShell Core). In order to change the categories, you’d want to run these commands:

        $ctx = Get-PnPContext
        $field = Get-PnPField -Identity "Category" -List "Events"
        $choiceField = New-Object Microsoft.SharePoint.Client.FieldChoice($ctx, $field.Path)
        $Ctx.Load($ChoiceField)
        Invoke-PnPQuery
 
        $ChoiceField.Choices = "Firm-wide"
        $ChoiceField.Choices += "Community"
        $ChoiceField.Choices += "Industry"
     

        $ChoiceField.UpdateAndPushChanges($True)
        Invoke-PnPQuery

Now one catch here is if you want to filter your Events WebPart to show only events of Category: Firm-wide.. when you filter by Firm-wide, you won’t get back any events back:

This won’t get you back any results

You would want to replace the – with space, so you’d filter by Firm wide:

This will work.

Note if you’re using other WebParts that depend on SharePoint Search (ex: Highlighted Content WebPart), you’ll want to filter the same way by replacing the – with space.

Hope this post helps someone out there!

Ciao!

Picture By: Andrei Stratu @avantgardian

Leave a Reply

Your email address will not be published. Required fields are marked *