0

When I try to get sub sites of specific sub site

var clientContext = SP.ClientContext('/groupcompanies');
var webs = clientContext.get_web().get_webs();

I get this error:

undefined is not a function >>>>> sp.js

While

var clientContext = SP.ClientContext.get_current();

works fine, there is always a problem when I define a url for ClientContext

0

1 Answer 1

2

This line

var clientContext = SP.ClientContext('/groupcompanies');

is incorrect, you need to create a new context, like this:

var clientContext = new SP.ClientContext('/groupcompanies');

(Notice the new keyword). Also make sure that /groupcompanies is a valid server relative path to a web.

2
  • It will be nice if u explain why SP.ClientContext.get_current() works without new keyword ? Commented Feb 8, 2015 at 17:21
  • Mainly because that is a contextual variable to have with you all the time (compare to the CurrentContext in server side code). When you want to create a context for another site you do not have that context and hence need to create a new object for that context. Commented Feb 8, 2015 at 18:47

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.