lundi 11 avril 2016

JavaScript Get SharePoint Online List from App

I have my SharePoint Online list on Site Collection level

mydomain/sites/dev/Lists/MyList

I am developing a custom SharePoint-hosted app which is on

mydomain/sites/dev/MyApp

I currently have this bit of javascript code:

var siteUrl = 'mydomain/sites/dev';
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('MyList');

And I get an error:

Request failed. List 'MyList' does not exist at site with URL 
mydomain/sites/dev/MyApp

So I need to reach the parent/root web somehow...

I've tried adding .get_rootWeb() like this

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

But then I get:

JavaScript runtime error: Object doesn't support property or method 'get_rootWeb'

Am I missing something?




Aucun commentaire:

Enregistrer un commentaire