Pergunta

Estou tentando obter o título de uma lista localizada no site host de um aplicativo hospedado no SharePoint usando csom (javascript).Adicionei permissão no arquivo de manifesto e escolhi a lista, mas ainda obtive acesso negado em executeQueryAsync.aqui está o meu código:

  hostweburl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
  var hostcontext = new SP.ClientContext(hostweburl);
  var oList = hostcontext.get_web().get_lists().getByTitle('SliderList');
  var camlQuery = new SP.CamlQuery();
  camlQuery.set_viewXml(' som query to get proper items')
  this.collListItem = oList.getItems(camlQuery);

   hostcontext.load(collListItem);

   hostcontext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

não vai para onQuerySuccess ou onQueryFailed, diz Acesso negado em SP_ClientRuntimeContext$executeQueryAsync, sp.runtime.debug.js, linha 3103

Foi útil?

Solução

Na verdade, você precisa gerar um SP.ClientContext para o aplicativo web e um SP.AppContextSite para o host da web.Para obter uma referência a uma lista no host web, tente o seguinte:

// Get the ClientContext for the app web
clientContext = new SP.ClientContext.get_current();
// Use the host web URL to get a parent context - this allows us to get data from the parent
hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
parentCtx = new SP.AppContextSite(clientContext, hostweburl);
parentWeb = parentCtx.get_web();
parentList = parentWeb.get_lists().getByTitle("SliderList");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a sharepoint.stackexchange
scroll top