Domanda

Sto cercando di ottenere il titolo di un elenco che si trova sul sito host da un'app di SharePoint Hosted utilizzando CSOM (JavaScript).Ho aggiunto il permesso sul file manifest e ho scelto l'elenco ma ancora l'accesso ha negato su ExecuteQueryyAsync.Ecco il mio codice:

  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));
.

Non va a nessuna ignitica o in eccesso, afferma l'accesso negato su sp_clientruntimecontext $ exectequeryyasync, sp.runtime.debug.js, linea 3103

È stato utile?

Soluzione

È effettivamente bisogno di generare un SP.ClientContext per il Web App Web e un sp.appcontextsite per il web host.Per ottenere un riferimento a un elenco nel Web host, prova quanto segue:

// 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");
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top