Apply SharePoint JSON View Formatting
Summary
This sample script shows how to apply SharePoint JSON view formatting using PnP PowerShell and CLI for Microsoft 365.
Scenario inspired from this blog post: SharePoint Online: Apply JSON View formatting using PnP PowerShell
# SharePoint online site URL
$siteUrl = "https://contoso.sharepoint.com/sites/SPConnect"
# Display name of SharePoint list
$listName = "Ganesh Sanap Blogs"
# Name of SharePoint list view
$viewName = "All Items"
# JSON to apply to view formatting
$jsonViewFormatting = @'
{
"$schema": "https://developer.microsoft.com/json-schemas/sp/view-formatting.schema.json",
"additionalRowClass": "=if([$PublishDate] <= @now && [$IsPublished] == false, 'sp-field-severity--severeWarning', '')"
}
'@
# Connect to SharePoint online site
Connect-PnPOnline -Url $siteUrl -Interactive
# Apply JSON view formatting
Set-PnPView -List $listName -Identity $viewName -Values @{CustomFormatter = $jsonViewFormatting}
Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell
The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?
Contributors
Author(s) |
---|
Ganesh Sanap |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.