I need to use the js for all views in all libraries in a site. Is there a way to deploy this in one hit rather than editing each view individually?
0
You can use powershell:
$site = Get-SPSite http://mysite
$web = $site.OpenWeb()
$list = $web.Lists["List Name"]
$wp = $list.RootFolder.Name + "/Forms/AllItems.aspx"
$wpManager = $website.GetLimitedWebPartManager($wp, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = $wpManager.WebParts[0]
$webpart.JSLink = "~SiteCollection/_catalogs/masterpage/myScript.js"
$wpManager.SaveChanges($webpart)
You can loop throught your lists to add the js script.
-
-
-
I am getting these errors You cannot call a method on a null-valued expression. Cannot index into a null array. The property 'JSLink' cannot be found on this object. Verify that the property exists and can be set. Any ideas? – Mike Blair Apr 23 '15 at 15:09
-
The
$webpart
is null execute the script line for line to check if you retrive the right object – Nk SP Apr 23 '15 at 15:11
1
Change $website to $web , the final script will look like below :
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$web = Get-SPWeb http://sharepointsite
$list = $web.Lists["TestJSLink"]
$wp = $list.RootFolder.Name + "/Forms/AllItems.aspx"
$wpManager = $web.GetLimitedWebPartManager($wp, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = $wpManager.WebParts[0]
$webpart.JSLink = "~layouts/XYZ/JSLink.js"
$wpManager.SaveChanges($webpart)
Write-Output "Done"