Office 365- El acceso a las listas se refiere URL incorrecta (Nombre de la URL / APLICACIÓN)
-
29-09-2020 - |
Pregunta
Soy nuevo en la herramienta NAPA.Comencé a construir aplicaciones simples usando Napa Herramienta.Y intenté acceder a una lista en el sitio de Office 365 usando el código inferior.Después de publicar la aplicación, muestra un mensaje de error: Mensaje: Lista 'Anuncios' no existe en el sitio con URL
https://URL/sites/DevSite/SharePointApp3
https://URL/sites/DevSite/
es mi sitio y SharePointApp3 es mi nombre de aplicación.De mirada
https://URL/sites/DevSite/
tiene la lista de anuncios y
https://URL/sites/DevSite/SharePointApp3
no tiene.¿Alguien puede sugerir resolver esto?
<script type="text/javascript">
//This example gets all the items in the Announcements list that have a title that begins with 'T'.
//If your site doesn't include a list called Announcements you must make the changes indicated
//This variable will hold a reference to the Announcements list items collection
var returnedItems = null;
//This function loads the list and runs the query asynchronously
function queryListItems() {
//Get the current context
var context = new SP.ClientContext();
//Get the Announcements list. Alter this code to match the name of your list
var list = context.get_web().get_lists().getByTitle('Announcements');
//Create a new CAML query
var caml = new SP.CamlQuery();
//Create the CAML that will return only items with the titles that begin with 'T'
caml.set_viewXml("<View><Query><Where><BeginsWith><FieldRef Name='Title' /><Value Type='Text'>T</Value></BeginsWith></Where></Query></View>");
//Specify the query and load the list oject
returnedItems = list.getItems(caml);
context.load(returnedItems);
//Run the query asynchronously, passing the functions to call when a response arrives
context.executeQueryAsync(onSucceededCallback, onFailedCallback);
}
//This function fires when the query completes successfully
function onSucceededCallback(sender, args) {
//Get an enumerator for the items in the list
var enumerator = returnedItems.getEnumerator();
//Formulate HTML from the list items
var markup = 'Items in the Announcements list that start with "T": <br><br>';
//Loop through all the items
while (enumerator.moveNext()) {
var listItem = enumerator.get_current();
markup += 'Item Title: ' + listItem.get_item('Title') + '<br>';
markup += 'Item ID: ' + listItem.get_id() + '<br><br>';
}
//Display the formulated HTML in the displayDiv element
displayDiv.innerHTML = markup;
}
//This function fires when the query fails
function onFailedCallback(sender, args) {
//Formulate HTML to display details of the error
var markup = '<p>The request failed: <br>';
markup += 'Message: ' + args.get_message() + '<br>';
//Display the details
displayDiv.innerHTML = markup;
}
</script>
Solución
Tienes que obtener el contexto del sitio donde tienes tu lista.El siguiente código debería funcionar:
var context = new SP.AppContextSite(SP.ClientContext.get_current(), 'https://URL/sites/DevSite/');
var list = context.get_web().get_lists().getByTitle('Announcements');
Editar: También deberá dar permiso para la aplicación en el Sitio (Web de host).Puede hacerlo en NAPA de las propiedades de la cinta izquierda -> Permisos.
Otros consejos
Supongo que necesita acceder a la lista de anuncios web de host, para hacerlo, debe obtener el contexto del cliente de la Web host incluso antes de hacer esto
var list = context.get_web().get_lists().getByTitle('Announcements');
Además, trate de leer algunas leyendo en la arquitectura de la aplicación de SharePoint.Cómo las aplicaciones web y la web host son diferentes.