Question

J'essaie d'obtenir le titre d'une liste qui se trouve sur le site hôte à partir d'une application hébergée SharePoint à l'aide de CSOM (JavaScript).J'ai ajouté la permission sur le fichier manifeste et j'ai choisi la liste, mais j'ai toujours accès refusé sur ExecuteQuéryAsync.Voici mon code:

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

Il ne va pas à l'autre surquysuccy ou surqueryFailed, il dit l'accès refusé sur sp_clientruntimecontext $ ExecuteQuyAsync, sp.Runtime.debug.js, ligne 3103

Était-ce utile?

La solution

Vous devez réellement générer un sp.clientContext pour le Web Web Web Web et un SP.AppContextsite pour le Web hôte.Pour obtenir une référence à une liste dans le Web hôte, essayez ce qui suit:

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à sharepoint.stackexchange
scroll top