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();


     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.

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

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
    This is most definately the correct error, using this is what kills the code Feb 6 '17 at 12:33

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.