Pregunta

Estoy tratando de obtener el título de una lista que se encuentra en el sitio de host desde una aplicación alojada SharePoint utilizando CSOM (JavaScript).He agregado permiso en el archivo manifiesto y eligió la lista, pero aún así recibe acceso denegado en ExecuteQueryasync.Aquí está mi 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));

No va a Onquerysuccess o OnQueryFailed, dice Access denegado en SP_ClientRuntimecontext $ ExecuteQueryasync, Sp.Runtime.debug.js, Línea 3103

¿Fue útil?

Solución

Realmente necesita generar un SP.ClentContext para la aplicación web y un sp.appcontextsite para la web host.Para obtener una referencia a una lista en la Web host, intente lo siguiente:

// 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 bajo: CC-BY-SA con atribución
scroll top