1

I have this code which is meant to get data from a list at the site collection level.

var clientContext = new SP.ClientContext.get_current();

    var oList = clientContext.get_site().openWeb().get_lists().getByTitle('ListName');
    var query = "query here";

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml(query);
    collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);

I had modified the lines below which gets data from the current web

var clientContext = new SP.ClientContext.get_current();


    var oList = clientContext.get_web().get_lists().getByTitle('ListName');

to this

var clientContext = new SP.ClientContext.get_current();

    var oList = clientContext.get_site().openWeb().get_lists().getByTitle('ListName');

Usually you open the site then the web and then get to the list but it doesn't seem to work in JS.

Can you please point out what I need to do fix it?

Thanks,

0

Use .get_site().get_rootWeb() instead of get_site().openWeb()

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.