Unable to hide site column from the New form using PnP
-
21-02-2021 - |
Question
I want to hide a site column from the New form, so i tried this PnP script:-
PS C:\WINDOWS\system32> Connect-PnPOnline -Url "https://***.sharepoint.com/sites/***/" -UseWebLogin
PS C:\WINDOWS\system32> $ctx = Get-PnPContext
PS C:\WINDOWS\system32> $field = Get-PnPField -Identity "ProjectDepartment"
PS C:\WINDOWS\system32> $field.SetShowInNewForm($false)
PS C:\WINDOWS\system32> $field.UpdateAndPushChanges($true)
PS C:\WINDOWS\system32> $ctx.ExecuteQuery()
Exception calling "ExecuteQuery" with "0" argument(s): "The node to be inserted is from a different document context."
At line:1 char:1
+ $ctx.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServerException
so i am not sure why i am getting the above error? altohugh i have a site column with internal name = "ProjectDepartment"!!? any advice?
La solution
Try this script instead:
Connect-PnPOnline -Url "https://***.sharepoint.com/sites/***/" -UseWebLogin
$fieldTitle = "ProjectDepartment"
$field = $ctx.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$field.SetShowInEditForm($true)
$ctx.ExecuteQuery()
$field.SetShowInNewForm($false)
$ctx.ExecuteQuery()
$field.UpdateAndPushChanges($true)
$ctx.ExecuteQuery()
Reference: SharePoint CSOM and “The node to be inserted is from a different document context.”.
Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange