I am working on a modern team site collection inside our sharepoint online tenant. I want to associate a JSLINK with a site column, so i run this PnP script:-

$User = "***@***.onmicrosoft.com"
$SiteURL = "https://***.sharepoint.com/sites/***/"

#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 = "ItemNumber"
$customfield = $Context.Site.RootWeb.Fields.GetByInternalNameOrTitle($fieldTitle)
$customfield.JSLink = "~siteCollection/siteassets/HideItemNumberInQuickEdit.js"

But i got this exception:-

Exception calling "ExecuteQuery" with "0" argument(s): "Unknown Error" At line:1 char:1 + $Context.ExecuteQuery() + ~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : ServerException

Here is a screen shot inside the SP online management shell:-

enter image description here

So can anyone help me in identifying the cause of this error?


  • Don't really know, but, why the two ExecuteQuery? I would remove the first one (the one is crashing) and perform the update before the executequery to make sure the change is attached to the context. – Gonzix Oct 16 '19 at 14:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.