Доступ к списку из App Web на хост-сайте генерирует доступ запрещен
-
10-12-2019 - |
Вопрос
Я пытаюсь получить название списка, который расположен на месте HOST, из приложенного приложения SharePoint, используя CSOM (JavaScript).Я добавил разрешение на файл MaineSt и выбрал список, но все же получение доступа, запрещенного на ExecuteVeryAsync.Вот мой код:
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));
.
Он не ходит ни к OnquerySuccess или OnqueryFailed, он говорит, что доступ запрещен на SP_CLIRTRUNTIMECONTEXT $ ExecuteVeryAsync, sp.runtime.debug.js, линия 3103
Решение
На самом деле вам нужно создать SP.ClientContext для веб-веб-сайта
.// 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");