Thursday, September 19, 2019

Procedure to hide SharePoint online list public views

We have a SharePoint site that is used by two different type of users. One type is admin who should be able to see list item. The other type is regular user who should see some list item based on the column value. We do not want to have item level permissions that will need additional development effort. Here is the quick solution.



  1. Create public view to exclude list item based on the column value. 
  2. Create another master view to display all items. 
  3. Add a page that is only be accessed by Admin group that has the link to the master view and include the master view.
  4. Use Powershell to hide the view from view selections.


#Install-Module SharePointPnPPowerShellOnline

#Change this to the URL of your SharePoint site
$sharePointUrl = "https://yourcompany.sharepoint.com/sites/sitename"

#Connect-PnPOnline –Url $sharePointUrl –Credentials (Get-Credential)

# open learner list
$listUrl = "Lists/listname"
$list = Get-PnPList -Identity $listUrl

$list.Context.Load($list.Views)
$list.Context.ExecuteQuery()

ForEach($v in $list.Views){

    if($v.Title -eq 'ListViewName'){ 
    $v.Hidden = $true;
    #$v.Hidden = $false;
    $v.Update()
    }
}

$list.Context.ExecuteQuery()

No comments:

Post a Comment