I have my app and my list in my site contents like so:
From my app, I'd like to read, write, and manipulate the data from TestList.
The contents of TestList are like so:
I've been trying to read it using this:
function setup() {
var context = SP.ClientContext.get_current();
var lists = context.get_web().get_lists();
var list = lists.getByTitle('TestList');
var listItem = list.getItemById("Title1"); // is Id the list title?
context.load(listItem);
context.executeQueryAsync(onLoadSuccess, onLoadFail);
console.log(listItem);
}
function onLoadFail(sender, args) {
alert(args.get_message());
console.log(args.get_message());
};
As well as some other methods outlined here and here , but I'm constantly greeted by the error:
List 'TestList' does not exist at site with URL ' https://mysite.sharepoint.com/sites/developer/TestApp '.
I think it could have something to do with TestList being an app within the same directory level as TestApp, not a list within TestApp which is why I included the pictures. However, I can't figure out how to embed TestList within TestApp.
My other concern with making the list within the app would be that whenever I update and redeploy TestApp, it would wipe any new updates to TestList.
Can someone see what I'm doing wrong or offer some suggestions? Thanks in advance.
you need to use right ClientContext.
var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl")); currentcontext = new SP.ClientContext.get_current(); hostcontext = new SP.AppContextSite(currentcontext, hostUrl); web = hostcontext.get_web(); // hostcontext instead of currentcontext var lists = web .get_lists(); var list = lists.getByTitle('TestList'); var listItem = list.getItemById(1); // Id is Id (number) context.load(listItem); context.executeQueryAsync(onLoadSuccess, onLoadFail);
more details: http://blog.appliedis.com/2012/12/19/sharepoint-2013-apps-accessing-data-in-the-host-web-in-a-sharepoint-hosted-app/
I think you are on the right track. It appears that you want to work with a list on the host web, but your are using an appweb endpoint. I can think of two options:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.