0
votes

I want to access the SharePoint 2013 Site Settings → Master Page/Navigation settings etc. using CSOM (Client-Side Object Model) from JavaScript or REST service or Webservice which I can call from Javascript. Can I get the pointer if such API/objects are available for SharePoint 2013?

To be more specific: I want to access and change the Site Setting → Navigation (under look and Feel) → Global and Current Navigation to "Structural Navigation" instead of "Managed Navigation". I want to achieve this using CSOM (Javascript / REST / Web Service). I don't want to use server side object model.

2
I think this is something closest you can get from Client Object Model: code.msdn.microsoft.com/SharePoint-2013-Assign-new-5c19062b . I expect, that it should be possible to do from javascript as well. If you can specify your problem in more details, maybe i will be able to help more.Marek Kembrowski
Thanks a lot @Marek Kembrowski !!! Let me explain my problem in detail: I want to access and change the Site Setting--> Navigation (under look and Feel)--> Global and Current Navigation to "Structural Navigation" instead of "Managed Navigation". I want to achieve this using CSOM (Javascript / REST/WebSErvice). I dont have any option to use server side or managed object model. I hope this might have give you a closer look to actual requirement. Thanks again!!! nksnks
In this case I don't know any way to achieve this (and I think there isn't any using Javascript/Webservices).Marek Kembrowski

2 Answers

1
votes

Perfectly working script for setting Master Page:

$(document).ready(function () { jQuery('.cmdSet').click(function () {

    var scriptBase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";

    $.getScript(scriptBase + "sp.runtime.js", function () {

        $.getScript(scriptBase + "sp.js", function () {

            $.getScript(scriptBase + "sp.core.js", sharePointReady);

        });
    });

});

});

// create page-level variables to hold client context and web
var context;
var web;
var masterurl;
var site;
function sharePointReady() {

// assign values to page-level variables
context = new SP.ClientContext.get_current();
web = context.get_web();

// provide CSOM with instructions to load info about current web


context.load(web, 'ServerRelativeUrl');
web.set_customMasterUrl(L_Menu_BaseUrl + '/_catalogs/masterpage/seattle.master');
web.set_masterUrl(L_Menu_BaseUrl + '/_catalogs/masterpage/seattle.master');
web.update();

context.executeQueryAsync(function () {

    alert("Starting Master Page Setting......");
    masterurl = web.get_serverRelativeUrl() + "/_catalogs/masterpage/seattle.master";
    alert(masterurl);
    alert("Master Page is Set Successfully!!!");

}, function (sender, args) {

    alert("Error: " + args.get_message());

});

}

0
votes

In SharePoint 2013 was introduced a new SP.Publishing.Navigation namespace (part of SharePoint Publishing JavaScript Library). In particular WebNavigationSettings class that is intended for managing the navigation settings for a publishing site.

The following example demonstrate how to set Global Navigation to display Structural Navigation:

function configureNavigation()
{
   var ctx = SP.ClientContext.get_current();         
   var web = ctx.get_web();
   var webNavSettings = new SP.Publishing.Navigation.WebNavigationSettings(ctx,web);

   var navigation = webNavSettings.get_globalNavigation();
   navigation.set_source(SP.Publishing.Navigation.StandardNavigationSource.portalProvider); //set to Structural Navigation   
   webNavSettings.update();

   ctx.executeQueryAsync(
        function(){
            console.log("Navigation settings have been updated successfully");  
        },function(sender,args){    
            console.log(args.get_message());
        });
}

Key points:

Usage

var scriptBase = _spPageContextInfo.webAbsoluteUrl + "/_layouts/15/";   
$.when(
    $.getScript( scriptBase + "sp.js" ),
    $.getScript( scriptBase + "sp.publishing.js" ),
    $.Deferred(function( deferred ){
        $( deferred.resolve );
    })
).done(function(){
     configureNavigation();    
});