Вопрос

I am retrieving lists using NAPA. The problem is that to whichever site or site collection I add the app, I always receive only

  • Composed Looks
  • Master Page Gallery

This is very few given that a C# or Powershell code ctx.Web.Lists usually returns ca. 10 default ones (Taxonomy, Solution Gallery, Assets, etc.). This leads me to think that the lists queried come from a site created by the app itself:

https://tenant-fced64b97322f5.sharepoint.com/sites/SiteCollection/SA181104/Pages/Default.aspx

I get the same results on all site collections. Full (almost) code:

var context = SP.ClientContext.get_current();
var web = context.get_web();
var lists = web.get_lists();

function listperms()
{
context.load(lists);
context.executeQueryAsync(onlistItemsSuccess, onWebPropsFail);

}

function onlistItemsSuccess(sender, args)
{

var listEnumerator = lists.getEnumerator();
while (listEnumerator.moveNext()) {
    // shows the title of the list
}

context.executeQueryAsync();
}

Questions:

  1. How to make the code retrieve all lists in a web?
  2. Why are there only 2 lists in the app site?
Это было полезно?

Решение

Every SharePoint app has its own SharePoint web associated with it. This is called the "App Web", and based on your code this is where the lists are coming from. Also, the SharePoint web on which the app was installed is usually known as "Host Web".

I don't know if you are trying to read the host web's list or the app web's lists, so here are an example for both.

App Web JSOM Code

var queryStringPairs = SP.ScriptHelpers.getDocumentQueryPairs();
var appweburl = queryStringPairs["SPAppWebUrl"];
var clientContext = new SP.ClientContext(appweburl);
var appWeb = clientContext.get_web();
var appWebLists = appWeb.get_lists();
clientContext.load(appWebLists);
clientContext.executeQueryAsync(onlistItemsSuccess, onWebPropsFail);

Host Web JSOM Code

var queryStringPairs = SP.ScriptHelpers.getDocumentQueryPairs();
var appweburl = queryStringPairs["SPAppWebUrl"];
var hostweburl = queryStringPairs["SPHostUrl"];
var clientContext = new SP.ClientContext(appweburl);
var proxyFac = new SP.ProxyWebRequestExecutorFactory(appweburl);
clientContext.set_webRequestExecutorFactory(proxyFac);
var appContextSite = new SP.AppContextSite(clientContext, hostweburl);
var hostWeb = appContextSite.get_web();
var hostWebLists = hostWeb.get_lists();
clientContext.load(hostWebLists);
clientContext.executeQueryAsync(onlistItemsSuccess, onWebPropsFail);

Also a sample project here

-Hope it helps

Лицензировано под: CC-BY-SA с атрибуция
Не связан с sharepoint.stackexchange
scroll top