0

Here is the JavaScript I'm currently using to set my Masterpage as the default Masterpage within my site. I'm running into a problem where I receive the onQuerySucceeded message after deploying the App. However, the Masterpage on the site does not update to the one specified within my App.

var context;
var web;
var user;

function sharePointReady() {
    updateMaster();
}
function updateMaster() {
    var clientContext = new SP.ClientContext.get_current();
    this.web = clientContext.get_web();
    this.web.set_masterUrl('/NavigationList/MasterPages/BootstrapTest.master');
    clientContext.load(this.web);
    clientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)
);
}

function onQuerySucceeded(sender, args) {
    alert('New Master Page set to: ' + this.web.get_masterUrl());
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

I have the permissions of the web and the site collection set to full control.

Any help would be appreciated.

  • Are you trying to change the master page of the App web or the Host web? – Rodrigo Molinas Mar 13 '15 at 14:49
  • I want to apply it to the host web. – Treebeards Mar 13 '15 at 15:05
1

The problem with your code is that you are generating the context for the App Web, but trying to change the master on the host web.

You need to change one line on the updateMaster method to use the app host web for creating the ClientContext. This url can be read from the query string.

function updateMaster() {
    var clientContext = SP.ClientContext(apphosturl);
    this.web = clientContext.get_web();
    this.web.set_masterUrl('/NavigationList/MasterPages/BootstrapTest.master');
    clientContext.load(this.web);
    clientContext.executeQueryAsync(
    Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

-Hope it helps

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.