2

I would like to hide a site column from appearing in the EditForm on SharePoint online.

I have been able to achieve this on SharePoint server 2010 by running the following PowerShell.

This will not work in SharePoint Online. Can anyone tell me what I'm doing wrong?

#Get the web and site column objects
$web = Get-SPWeb http://<URL>
$column = $web.Fields["ColumnName"]

#Set the PushChangesToLists property for the changes to be applied to lists where the column has already been added
$column.PushChangesToLists = $true

#Change the ShowInEditForm and other properties and update objects
$column.ShowInEditForm = $false

$column.Update()
$web.Update()
$web.Dispose() 
2

You need to use SharePoint online PowerShell.

In that powershell, try below code:

$User = "admin@tenant.onmicrosoft.com"
$SiteURL = https://tenant.sharepoint.com/sites/site #enter site collection url


#Add references to SharePoint client assemblies and authenticate to Office 365 site – required for CSOM
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)

#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds

$fieldTitle = "ColumnName"
$customfield = $Context.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle) 
$customfield.ShowInEditForm($false)
$customfield.UpdateAndPushChanges($true)

$Context.ExecuteQuery()

Download & install the SharePoint client component SDK which will give you the CSOM dlls.

Also download the SP online management shell to run the above code.

SharePoint 2013 Client component SDK

SharePoint online management shell

  • 3
    This won't work but only a minor change is required: $customfield.SetShowInEditForm($false) For some weird reason it is method in SPO and not a property. – Bunzab Dec 1 '16 at 19:34
  • Absolutely dynamite. That worked a treat. Cheers both. – jahlive Dec 5 '16 at 13:15
  • Why the script initializes $Creds two times? – spoonboy Jun 30 '17 at 1:08
  • What if there are multiple fields with the same name in different lists? How to specify the list name? – spoonboy Jun 30 '17 at 1:59
  • @spoonboy - can you ask this in a separate question ? Would gladly answer it there. Its out of scope for this question and my answer would be too long for the comment section :) – Gautam Sheth Jun 30 '17 at 19:46
0

With PnP PowerShell Cmdlets

Connect-PnPOnline <tenant-site-url>

$ctx = Get-PnPContext
$field = Get-PnPField -Identity <field-name> -List <list-name>

$field.SetShowInNewForm($false)
$field.Update()
$ctx.ExecuteQuery()

To check if the update took, look for ShowInNewForm="FALSE" in schema xml

$field.SchemaXml

To install PnP Powershell Cmdlets

https://docs.microsoft.com/en-us/powershell/sharepoint/sharepoint-pnp/sharepoint-pnp-cmdlets?view=sharepoint-ps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.