1

I'm really having trouble debugging this simple task: Read items from the host web in an app.

I've tried several examples but getting various errors. Problem is that the errors are in Norwegian. That is really difficult to debug...

This is my code:

var context = new SP.ClientContext(appweburl);
var appContextSite = new SP.AppContextSite(context, hostweburl);
var list = appContextSite.get_web().get_lists().getByTitle('List1');
itemsInlist = list.getItems();
context.load(itemsInlist);
context.executeQueryAsync(....)

And in my error handler I get this error "Ukjent feil" (it translates to "unknown error"). The error is read out from a call to args.get_message()

If I instead only list items query for all lists i get the expected lists returned. But to get the actual list items - that seems to be impossible...

Yes, I've given the correct access - full control to list when installin the app.

(The code above is fetched from this link. I've also tried several other samples. They work for getting the lists, but not the list items. )

I be really happy if someone could provide some hints on what to try.

2

one possible reason is that you need a CamlQuery object as a parameter when you call list.getItems() (MSDN). If you miss it, you will get a "Unknown Error" from args.get_message().
So, to make it work, you can simply initialize a new CamlQuery object, and change your code to:

var context = new SP.ClientContext(appweburl);
var appContextSite = new SP.AppContextSite(context, hostweburl);
var list = appContextSite.get_web().get_lists().getByTitle('List1');
var query = new SP.CamlQuery();
itemsInlist = list.getItems(query);
context.load(itemsInlist);
context.executeQueryAsync(....)

If you want to support filtering or sorting in query, you can call:

query.set_viewXml("your caml");  

before list.getItems(query). For more information about how to retrieve list items, you can check here. Hope it's helpful.

  • Thanks, yes that was the cause. Guess I should start reading the docs and not just copy past code. – Larsi Jan 8 '14 at 18:51
  • @Larsi You're welcome, I'm glad it solves your problem. – Xiaodan Mao Jan 9 '14 at 0:35

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.