Question

I'm trying to create a SharePoint hosted app that creates a subsite under the hostweb with JSOM. The app has full control on the site collection. Why do i I getting this error message:

enter image description here enter image description here

My code:

function createWebsite() {

var clientContext = new SP.ClientContext('http://sp2013/sites/dev');
this.oWebsite = clientContext.get_web();

var webCreationInfo = new SP.WebCreationInformation();
webCreationInfo.set_title('My New Web Site');
webCreationInfo.set_description('Description of new Web site...');
webCreationInfo.set_language(1033);
webCreationInfo.set_url('MyNewWebSite');
webCreationInfo.set_useSamePermissionsAsParentSite(true);
webCreationInfo.set_webTemplate('STS#0');

oWebsite.get_webs().add(webCreationInfo);
oWebsite.update();
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),Function.createDelegate(this, this.onQueryFailed));
}
Was it helpful?

Solution

Yes, but no, the app does not have full control. The app has permissions to execute code in full control only if the user executing the code has full control of the Site collection.

So you must make sure that the users has permissions to create a subsite as well. You can not elevate permissions in a SharePoint hosted app, for that you must CSOM in C#

OTHER TIPS

SharePoint hosted apps do not have access to oAuth, and get their permissions from the user.

If you wish to give permissions to the app you must use a provider hosted or auto hosted app.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top