Domanda

Sono nuovo allo strumento Napa.Ho iniziato a costruire semplici app usando Napa Tool.E ho provato ad accedere a una lista nel sito Office 365 utilizzando il seguente codice.Dopo aver pubblicato l'app mostra un messaggio di errore: Messaggio: elenco 'annunci' non esiste sul sito con URL

https://URL/sites/DevSite/SharePointApp3

https://URL/sites/DevSite/
.

Il mio sito e SharePointApp3 è il mio nome dell'app.A GLANCE

https://URL/sites/DevSite/
.

ha un elenco di annunci e

https://URL/sites/DevSite/SharePointApp3
.

non ha.Qualcuno può suggerire di risolvere questo.

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

È stato utile?

Soluzione

Devi ottenere il contesto del sito in cui hai la tua lista.Il seguente codice dovrebbe funzionare:

var context = new SP.AppContextSite(SP.ClientContext.get_current(), 'https://URL/sites/DevSite/');
var list = context.get_web().get_lists().getByTitle('Announcements');
.

Modifica: dovrai anche dare il permesso per l'app sul sito (web host).Puoi farlo a Napa dalle proprietà del nastro sinistro -> Autorizzazioni.

Altri suggerimenti

Assumendo che sia necessario accedere ad accedere all'elenco di annuncio Web host, per farlo è necessario ottenere il contesto client del Web host anche prima di farlo

var list = context.get_web().get_lists().getByTitle('Announcements');
.

Inoltre, prova a fare qualche lettura sull'architettura dell'app SharePoint.Come il web web e host dell'app sono diversi.

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