3

As the title says, I currently have JavaScript that sets the navigation, however it currently sets it too "Structural Navigation: Display the current site, the navigation items below the current site, and the current site's siblings" I cant seem to get it to set too "Structural Navigation: Display only the navigation items below the current site"

We are using a SharePoint online environment and we have built the javascript into the page layout.

This is the code I currently have:

$(document).ready(function(){

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

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

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

            $.getScript(scriptBase + "sp.publishing.js", modifyNavigation);

        });
    });

function modifyNavigation(){


    var context = SP.ClientContext.get_current();


    var currentWeb = context.get_web();     


    var webNavSettings = new SP.Publishing.Navigation.WebNavigationSettings(context, currentWeb);


    var navigation = webNavSettings.get_currentNavigation(); 

    navigation.set_source(1);

    webNavSettings.update();

    context.executeQueryAsync(function(){

        console.log("Navigation set");  

    },function(sender,args){

        alert(args.get_message());

    });


}   

With this code I end up with the following result: Navigation

Is it possible to have the code set the bottom radio button?

Any help is appreciated.

3

Not sure if that's still actual, but I found the solution to this problem.

In addition to setting the WebNavigationSettings.CurrentNavigation.Source to "PortalProvider", which you do in your code by calling

navigation.set_source(1); 

you also need to update the property "__NavigationShowSiblings" of the web object.

e.g. in PowerShell you can do this (and it works):

$web.AllProperties["__NavigationShowSiblings"] = "False";   
$web.Update()
$ctx.Load($web.AllProperties)
$ctx.ExecuteQuery()

In JSOM I think you could do something like this (haven't tried but found the snippet)

var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
this.properties = web.get_allProperties();
this.properties.set_item("__NavigationShowSiblings", "False");
ctx.load(web);
web.update();

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.