Forum Discussion
Method invocation failed because [Microsoft.SharePoint.Client.Field] doesn't contain a method named
We have a classic sharepoint team site collection. and we have a field named "AutomaticallyCreated" which is set a hidden inside the Create, Edit and Display forms. now i want to show the field inside the Edit & Display forms, so i run the "SharePoint Online Management Shell" as admin, then i run the following script:-
$User = "admin@****.onmicrosoft.com"
$SiteURL = "https://***.sharepoint.com/sites/**** #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 "enterpassword" -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 = "AutomaticallyCreated"
$customfield = $Context.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$customfield.ShowInEditForm($true)
$customfield.ShowInDisplayForm($true)
$customfield.UpdateAndPushChanges($true)
$Context.ExecuteQuery()
But i got this exception:-
Method invocation failed because [Microsoft.SharePoint.Client.Field] doesn't contain a method named 'ShowInEditForm'. At line:1 char:1 + $customfield.ShowInEditForm($true) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound Method invocation failed because [Microsoft.SharePoint.Client.Field] doesn't contain a method named 'ShowInDisplayForm'. At line:1 char:1 + $customfield.ShowInDisplayForm($true) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound
so can anyone advice on this please? as i know sharepoint fields should have methods named 'ShowInEditForm'. & "'ShowInDisplayForm'."
1 Reply
- fainpabloBrass Contributor
Hi,
Could you please try:
$customfield.SetShowInEditForm($true)
$customfield.SetShowInDisplayForm($true)Instead of:
$customfield.ShowInEditForm($true)
$customfield.ShowInDisplayForm($true)