I want the code snippet for Getting the list items and Show it in the App page. I'm creating SharePoint hosted app for Office 365. How do i get the list item values?

Thanks in Advance


With this code you can retrieve all element from YourList, you have change the name of the list in the var list. i hope this code help you!

var appURL = decodeURIComponent(getQueryString("SPAppWebUrl"));
var hostURL = decodeURIComponent(getQueryString("SPHostUrl"));

function getItemList(){
   var ctx = new SP.ClientContext(appURL);
    var appCtxSite = new SP.AppContextSite(ctx, hostURL);
    var web = appCtxSite.get_web();
    var list = web.get_lists().getByTitle("YourList");
    var query = new SP.CamlQuery();
    query.set_viewXml("<View><Query><Where><IsNotNull><FieldRef Name='Title' /></IsNotNull></Where></Query></View>");
    var listItemToUpdate = list.getItems(query);
        Function.createDelegate(this, function () {
            var listEnumerator = listItemToUpdate.getEnumerator();
            while (listEnumerator.moveNext()) {
                console.log("Item: " + listEnumerator.get_current().get_item("Title"));
        Function.createDelegate(this, function () {
function getQueryString(queryString) {
    var params = document.URL.split("?")[1].split("&");
    for (var i = 0; i < params.length; i++) {
        var query = params[i].split("=");
        var req = query[0];
        var result = query[1];
        if (req == queryString)
            return result;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.