0

I have a SharePoint list and I need to get all items from that list without using CAML Query in JSOM.

How can I do this?

  • If you really want to avoid using CAML, check this old post on using Search from JSOM. But honestly, calling getItems on the list with a nearly empty CAML is far easier: <Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query> – willman Jan 7 at 21:15
  • Also you can use REST calls to retrieve data – Raf Jan 8 at 4:58
1

Try using your code something like below:

var oListItems;

function GetAllListItems() {
    // You can optionally specify the Site URL here to get the context
    // If you don't specify the URL, the method will get the context of the current site
    // var clientContext = new SP.ClientContext("http://MyServer/sites/SiteCollection");
    clientContext = new SP.ClientContext();

    var oWeb = clientContext.get_web();

    // Specify list title here
    var oList = oWeb.get_lists().getByTitle("List Name");

    // Get all list items from the list
    // This method will get all the items from all the folders and sub folders including folders and sub folders too
    oListItems = oList.getItems(SP.CamlQuery.createAllItemsQuery());

    // Load list items to Client Context
    clientContext.load(oListItems);

    // Execute the query to the server.
    clientContext.executeQueryAsync(onsuccess, onfailed);
}

function onsuccess() {

    // Iterate through Enumerator
    var oEnumerator = oListItems.getEnumerator();

    while (oEnumerator.moveNext()) {
        // get_item("ColumnName")
        var oListItem = oEnumerator.get_current().get_item('Title');
        console.log("Name : " + oListItem);
    }
}

function onfailed(sender, args) {
    console.log('Failed' + args.get_message() + '\n' + args.get_stackTrace());
}

Reference: Get All Items in SharePoint using JSOM.

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.