1

I have the following piece of JS code that shows All Views associated with a SharePoint list (without having to use the contextual menu):

<script type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(IncreaseSurfacePivotCount, 'clienttemplates.js');

function IncreaseSurfacePivotCount() {
ClientPivotControl.prototype.SurfacedPivotCount = 4;
};
</script>

This code works flawlessly when pasted inside a script editor web part. Since I'll need to edit the pivot count periodically when new views are added, I'd prefer to save this code within my Site Assets folder and reference it instead.

Here is what I've tried unsuccessfully:

  1. Saved above snippet in Notepad++ as Show_All_Views.js
  2. Stored file in Site Assets folder. This folder is named SiteAssets (DC)
  3. Inserted Script Editor Web Part on the pages and used the following:
<script type="text/javascript" src="../SiteAssets%20(DC)/Show_All_Views.js"></script>

Can someone help understand what I'm doing wrong. I've followed the instructions in this similar thread exactly.

1
  • Please use 'Developer tools' in your browser, if not used already, to understand, 1. if the script is loaded fine from your asset folder, 2. if there are any JavaScript errors while loading. Using developer tools should help you debug the issue.
    – UBK
    May 5, 2020 at 22:12

1 Answer 1

0

Well, one thing for sure is, in the path in your src attribute, you are missing a reference to the Site Assets library itself, you are only referencing your folder within the Site Assets library. So the first thing you could try would be to make it:

<script type="text/javascript" src="../SiteAssets/SiteAssets%20(DC)/Show_All_Views.js"></script>

The second thing you could try is using the entire server relative URL. I usually do that because I find it more reliable than using relative paths with ../, so something like

<script type="text/javascript" src="/sites/MySite/MySubSite/SiteAssets/SiteAssets%20(DC)/Show_All_Views.js"></script>

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.