0

Is it possible to retreive all the items from different list in SharePoint? I know how to retreive list items from 1 list but not multiple lists.

var mylist = this.web.get_lists().getByTitle('Employees');
1

Yes, you can look though all lists and get list items one by one.

var clientContext = SP.ClientContext.get_current();
var web = clientContext.get_web();
var lists = web.get_lists();

clientContext.load(lists);
clientContext.executeQueryAsync(function () {
    var enumerator = lists.getEnumerator();
    var listItemsCollection = [];

    while (enumerator.moveNext()) {
        var list = enumerator.get_current();

        // Add your own truth test here or remove it if you want to query all lists
        if (list.get_baseTemplate() === 100) {
            var camlQuery = new SP.CamlQuery();
            var listItems = list.getItems(camlQuery);

            listItemsCollection.push(listItems);
            clientContext.load(listItems);
        }
    }

    clientContext.executeQueryAsync(function () {
        // Now you can access the array of SP.ListItemCollection
        for (var i = 0, length = listItemsCollection.length; i < length; i++) {
            var items = listItemsCollection[i];
            var enumerator = items.getEnumerator();

            while (enumerator.moveNext()) {
                var listItem = enumerator.get_current();

                console.log(listItem.get_item('Title'));
            }
        }
    }, function (sender, args) {
        alert(args.get_message());
    });
}, function (sender, args) {
    alert(args.get_message());
});
2
  • Thank you so much Xiaodan! Do you know how to query only items that the current user has created? I tried with something like this var camlQuery = new SP.CamlQuery(); var textCAML = '<View><Query><Where><Eq><FieldRef Name='Author'/></Eq></Where></Query></View>'; camlQuery.set_viewXml(textCAML);
    – Sunreuz
    Sep 29 '15 at 17:10
  • @Sunreuz Please try this: var textCAML = '<View><Query><Where><Eq><FieldRef Name=\'Author\'/><Value Type=\'Text\'>your user</Value></Eq></Where></Query></View>'; You didn't specify the value of Author field. Sep 30 '15 at 0:26
-1

use sharepoint rest api

/_api/web/lists

/_api/web/lists/GetByTitle('Test')

https://msdn.microsoft.com/en-us/library/office/dn531433.aspx

1
  • your solution will get items from a particular list only not all lists as per question. Feb 2 '17 at 8:14

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.