1

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?

1 Answer 1

2

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.”.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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