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?