Exception calling "ExecuteQuery" with "0" argument(s): "The node to be inserted is from a different

%3CLINGO-SUB%20id%3D%22lingo-sub-779537%22%20slang%3D%22en-US%22%3EException%20calling%20%22ExecuteQuery%22%20with%20%220%22%20argument(s)%3A%20%22The%20node%20to%20be%20inserted%20is%20from%20a%20different%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-779537%22%20slang%3D%22en-US%22%3E%3CP%3ELast%20week%20i%20was%20able%20to%20hide%202%20site%20columns%20from%20New%20list%20form%20using%20this%20PnP%20script%20(the%20fields%20were%20of%20type%20Single%20line%20of%20text%20and%20Date%2FTime)%3A-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E%24User%20%3D%20%22admin%40****.onmicrosoft.com%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24SiteURL%20%3D%20%22https%3A%2F%2F****.sharepoint.com%22%20%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%23Add%20references%20to%20SharePoint%20client%20assemblies%20and%20authenticate%20to%20Office%20365%20site%20%E2%80%93%20required%20for%20CSOM%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C15%5CISAPI%5CMicrosoft.SharePoint.Client.dll%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C15%5CISAPI%5CMicrosoft.SharePoint.Client.Runtime.dll%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24Password%20%3D%20Read-Host%20-Prompt%20%22enterpassword%22%20-AsSecureString%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24Creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24User%2C%24Password)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%23Bind%20to%20site%20collection%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24Context%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24SiteURL)%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24Creds%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24User%2C%24Password)%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24Context.Credentials%20%3D%20%24Creds%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%24fieldTitle%20%3D%20%22ProjectNumber%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24customfield%20%3D%20%24Context.Site.RootWeb.Fields.GetByInternalNameOrTitle(%24fieldTitle)%20%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24customfield.SetShowInEditForm(%24true)%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24customfield.SetShowInNewForm(%24false)%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%24customfield.UpdateAndPushChanges(%24true)%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%3CSTRONG%3E%24Context.ExecuteQuery()%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ebut%20today%20when%20i%20try%20the%20above%20script%20to%20hide%20a%20site%20column%20of%20type%20drop-down%20on%20the%20same%20site%20collection%26gt%3B%26gt%3B%20i%20got%20this%20error%20on%20the%20%3CSTRONG%3E%24Context.ExecuteQuery()%3C%2FSTRONG%3E%2C%20as%20follow-%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3EPS%20C%3A%5Cwindows%5Csystem32%26gt%3B%20%24Context.ExecuteQuery()%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EException%20calling%20%22ExecuteQuery%22%20with%20%220%22%20argument(s)%3A%20%22The%20node%20to%20be%20inserted%20is%20from%20a%20different%20document%20context.%22%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3EAt%20line%3A1%20char%3A1%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%2B%20%24Context.ExecuteQuery()%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%2B%20~~~~~~~~~~~~~~~~~~~~~~~%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%2B%20CategoryInfo%20%3A%20NotSpecified%3A%20(%3A)%20%5B%5D%2C%20MethodInvocationException%3C%2FSTRONG%3E%3CBR%20%2F%3E%3CSTRONG%3E%2B%20FullyQualifiedErrorId%20%3A%20ServerException%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20822px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F124966i66AF4FE11B940D11%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22errrrrrrrrrrrrrrrrro2.png%22%20title%3D%22errrrrrrrrrrrrrrrrro2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Enow%20i%20do%20not%20think%20the%20issue%20is%20with%20the%20field%20type%2C%20as%20i%20usually%20hide%20drop-down%20column%20using%20this%20PnP%20script%20without%20any%20issue..%20but%20not%20sure%20what%20is%20going%20on%2C%20as%20this%20script%20was%20working%20for%20me%20last%20week%20(4-5%20days%20ago!!).%3C%2FP%3E%3CP%3EThanks%20in%20advance%20for%20any%20help%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-779537%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPnP%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-781369%22%20slang%3D%22en-US%22%3ERe%3A%20Exception%20calling%20%22ExecuteQuery%22%20with%20%220%22%20argument(s)%3A%20%22The%20node%20to%20be%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-781369%22%20slang%3D%22en-US%22%3ECould%20you%20try%20to%20see%20what%20happens%20if%20you%20separate%20the%20changes%20of%20SetShowInEditForm%20and%20SetShowInNewForm%3F%20Changing%20your%20code%20as%20follows%3A%3CBR%20%2F%3E%3CBR%20%2F%3E%24customfield.SetShowInEditForm(%24true)%3CBR%20%2F%3E%24customfield.UpdateAndPushChanges(%24true)%3CBR%20%2F%3E%24Context.ExecuteQuery()%3CBR%20%2F%3E%3CBR%20%2F%3E%24customfield.SetShowInNewForm(%24false)%3CBR%20%2F%3E%24customfield.UpdateAndPushChanges(%24true)%3CBR%20%2F%3E%24Context.ExecuteQuery()%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-781745%22%20slang%3D%22en-US%22%3ERe%3A%20Exception%20calling%20%22ExecuteQuery%22%20with%20%220%22%20argument(s)%3A%20%22The%20node%20to%20be%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-781745%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1803%22%20target%3D%22_blank%22%3E%40Paul%20Pascha%3C%2FA%3Eyes%20this%20worked%20for%20me!!%20not%20sure%20what%20is%20going%20on%3F%20any%20idea%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-781801%22%20slang%3D%22en-US%22%3ERe%3A%20Exception%20calling%20%22ExecuteQuery%22%20with%20%220%22%20argument(s)%3A%20%22The%20node%20to%20be%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-781801%22%20slang%3D%22en-US%22%3EI%20don't%20know%20exactly%20what's%20going%20on%2C%20but%20I%20can%20imagine%20executing%20both%20operations%20in%20a%20single%20call%20to%20executequery%20results%20in%20some%20kind%20of%20conflict%20internally.%3C%2FLINGO-BODY%3E
Valued Contributor

Last week i was able to hide 2 site columns from New list form using this PnP script (the fields were of type Single line of text and Date/Time):-

 

$User = "admin@****.onmicrosoft.com"
$SiteURL = "https://****.sharepoint.com"
#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 = "ProjectNumber"
$customfield = $Context.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$customfield.SetShowInEditForm($true)
$customfield.SetShowInNewForm($false)
$customfield.UpdateAndPushChanges($true)

$Context.ExecuteQuery()

 

but today when i try the above script to hide a site column of type drop-down on the same site collection>> i got this error on the $Context.ExecuteQuery(), as follow-

 

PS C:\windows\system32> $Context.ExecuteQuery()
Exception calling "ExecuteQuery" with "0" argument(s): "The node to be inserted is from a different document context."
At line:1 char:1
+ $Context.ExecuteQuery()
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ServerException

 

errrrrrrrrrrrrrrrrro2.png

now i do not think the issue is with the field type, as i usually hide drop-down column using this PnP script without any issue.. but not sure what is going on, as this script was working for me last week (4-5 days ago!!).

Thanks in advance for any help

3 Replies
Could you try to see what happens if you separate the changes of SetShowInEditForm and SetShowInNewForm? Changing your code as follows:

$customfield.SetShowInEditForm($true)
$customfield.UpdateAndPushChanges($true)
$Context.ExecuteQuery()

$customfield.SetShowInNewForm($false)
$customfield.UpdateAndPushChanges($true)
$Context.ExecuteQuery()

@Paul Paschayes this worked for me!! not sure what is going on? any idea?

I don't know exactly what's going on, but I can imagine executing both operations in a single call to executequery results in some kind of conflict internally.