In SharePoint 2013 Developer Site:
I am installing an app to my site and it worked fine with default stuff. I added some custom .js file in this app which will set the master page of site coll and deployed again. I am able to open it once, but not able to set the master page. And from 2nd time onwards it always gives be below error:
**Sorry, there was a problem with FinanceConfigApp
For support, please contact the developer. Accessing referenced file https://microsoft-e25da8eeaa88f2.sharepoint.com/teams/NaveenDevSite/_catalogs/masterpage/seattle.master from https://microsoft-e25da8eeaa88f2.sharepoint.com/teams/NaveenDevSite/FinanceConfigApp/Pages/Default.aspx?SPHostUrl=https://microsoft.sharepoint.com/teams/NaveenDevSite&SPLanguage=en-US&SPClientTag=3&SPProductNumber=15.0.4454.1026&SPAppWebUrl=https://microsoft-e25da8eeaa88f2.sharepoint.com/teams/NaveenDevSite/FinanceConfigApp is not allowed because the reference is outside of the App Web.**
Any help would be highly appreciated!!!
I have tried: hardcoded the client context like below:
context = new SP.ClientContext('/teams/NaveenDevSite');
context = new SP.ClientContext('https://microsoft.sharepoint.com/teams/NaveenDevSite');
context = new SP.ClientContext.get_current();
below is the complete code which works perfect in my page. but not in App:
$(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);
});
});
});
});
var context;
var web;
var masterurl;
var site;
function sharePointReady() {
context = new SP.ClientContext.get_current();
web = context.get_web();
context.load(web, 'ServerRelativeUrl');
var splitBaseUrl = L_Menu_BaseUrl.split('/');
var baseUrl = '/' + splitBaseUrl[1] + '/' + splitBaseUrl[2];
web.set_customMasterUrl(baseUrl + '/_catalogs/masterpage/seattle.master');
web.set_masterUrl(baseUrl + '/_catalogs/masterpage/seattle.master');
web.update();
context.executeQueryAsync(function () {
masterurl = web.get_serverRelativeUrl() + "/_catalogs/masterpage/seattle.master";
alert("Master Page is Set Successfully!!!");
}, function (sender, args) {
alert("Error: " + args.get_message());
});
}