5

I have a custom list on root level site in SharePoint Online. I want to display the list data to one of my subsite pages.

I am using JSOM. How can I achieve this?

Following is my code which gets the data from the current site. But I want to fetch it from the root level site.

context = SP.ClientContext.get_current();
list = context.get_web().get_lists().getByTitle(listName);
7

Get the root site url as shown below:

var siteUrl = _spPageContextInfo.siteAbsoluteUrl;

Get client context using that url as shown below:

var context = new SP.ClientContext(siteUrl);
list = context.get_web().get_lists().getByTitle(listName);

Hope this will help you!

6

This could help

var context = new SP.ClientContext.get_current();         
var web = context.get_web();                        
var parentInfo = web.get_parentWeb();   
var parentWeb = context.get_site().openWebById(parentInfo.get_id());

context.load(parentInfo); context.load(parentWeb);
4

By using the following code you can get the root web :

var clientContext = new SP.ClientContext.get_current();
this.oSite = clientContext.get_site();
this.oWebsite = this.oSite.get_rootWeb();
clientContext.load(this.oWebsite);
clientContext.load(this.oSite);

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.