Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

JS script not working on Read users

$
0
0

I have this script to change the number of items to show in Content Search Web Part

function loadScript(selectObject) {

  var newItems = parseInt(selectObject.value);
  var pageUrl = _spPageContextInfo.serverRequestPath;
  var currentCtx = new SP.ClientContext.get_current();
  var pageFile = currentCtx.get_web().getFileByServerRelativeUrl(pageUrl);
  var webPartManager = pageFile.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
  var webPartDefs = webPartManager.get_webParts();

  currentCtx.load(webPartDefs, 'Include(WebPart.Properties)');
  currentCtx.executeQueryAsync(
      function () {
          if (webPartDefs.get_count()) {
              for (var i = 0; i < webPartDefs.get_count(); i++) {
                  var webPartDef = webPartDefs.getItemAtIndex(i);
                  var webPart = webPartDef.get_webPart();
                  var properties = webPart.get_properties();
                  if (properties.get_fieldValues().Title.indexOf("Content Search") > -1) {
                      properties.set_item("ResultsPerPage", newItems);
                      webPartDef.saveWebPartChanges();
                      currentCtx.load(webPartDef);
                      currentCtx.executeQueryAsync(
                          function () {
                              console.log("Web Part properties saved.");
                              location.replace("My Page.aspx");
                          },
                          function (err) {
                              console.log(err);
                          });
                  }
              }
          }
          else {
              console.log("No Web Parts Found.");
          }
      },
      function (sender, args) {
          console.log(args.get_message());
      });
}

But is only working for some users, I realized that the users with 'Read' (or less) permissions are the users facing this issue. What else should be done in order to get this working correctly for these users? Any workaround available?

I performed debug on Dev Tools, no errors, actually I can see console.log and the location.replace is performed.


Carlos M


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>