3

Below is my code for creating sub site in SharePoint Hosted App:

function createWebsite() 
{
     var clientContext = new SP.ClientContext("https://rootSite/sites/Site1");
     this.oWebsite = clientContext.get_web();
     var webCreationInfo = new SP.WebCreationInformation();
     webCreationInfo.set_title(projectName);
     webCreationInfo.set_language(1033);
     webCreationInfo.set_url('RM4');
     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));

}

But the site isn't created. I am getting error

enter image description here

Is it like anything that we can't use ClientContext in SP hosted app?

Any help would be appreciated.

6
  • Have you set the proper app permissions in AppManifest.xml ? Commented Feb 6, 2017 at 11:56
  • This is not a way to create client context in SP hosted add ins. codeproject.com/Articles/841321/…
    – Amit
    Commented Feb 6, 2017 at 11:57
  • @Ronak - Yes. Given Full control to Tenant and site Collection
    – DRS
    Commented Feb 6, 2017 at 11:58
  • @Amit - Can you please tell me the way how to create it
    – DRS
    Commented Feb 6, 2017 at 11:58
  • In code project link i have shared they have mentioned it. Please check if it helps.
    – Amit
    Commented Feb 6, 2017 at 12:00

1 Answer 1

0

From your screenshot this looks like non-sharepoint issue.. The code at the screenshot is not the same as the function that you pasted, so we cannot be sure in which scope it's running..

You should try to rewrite that line to:

var oWebsite = clientContext.get_web();
1
  • 1
    This is most definately the correct error, using this is what kills the code Commented Feb 6, 2017 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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