Wednesday, September 12, 2012

Hide a column from List Edit Form



I wanted to hide a column from Edit form of a specific list   

function Hide-SPField([string]$url, [string]$List, [string]$Field) {
 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
 $SPSite = New-Object Microsoft.SharePoint.SPSite($url)
 $OpenWeb = $SPSite.OpenWeb()
 $OpenList = $OpenWeb.Lists[$List]
 $OpenField = $OpenList.Fields[$Field]
 $OpenField.ShowInNewForm = $True
 $OpenField.ShowInEditForm = $False
 $OpenField.ShowInViewForms = $True
 $OpenField.ShowInDisplayForm = $True
 $OpenField.Update()
 $SPSite.Dispose()
 $OpenWeb.Dispose()
 }

 Hide-SPField -url http://yoursite.com/ -List "ListName" -Field "ColumnName"

If you want to hide column in forms across the entire site. you need set the PushChangesToLists property for the changes to be applied to lists where the column has already been added.




#Get the web and site column objects
 $web = Get-SPWeb "http://yoursite.com
 $column = $web.Fields["ColumnName"]
$column.PushChangesToLists = $true
 #Change the ShowInForm property and update objects
 $column.ShowInEditForm = $False
 $column.ShowInNewForm = $False
 $column.ShowInViewForms = $False
 $column.ShowInDisplayForm = $False
 $column.Update()
 $web.Update()
 $web.Dispose()





No comments:

Post a Comment