Share via

Question about "SP.CamlQuery.createAllItemsQuery()"

john john Pter 1,550 Reputation points
2026-06-07T11:49:19.3066667+00:00

I have a JavaScript code that retrieve items from sharepoint online custom list as follow:-

var camlQuery = SP.CamlQuery.createAllItemsQuery();
meetingExpendituresOList = clientContext.get_web().get_lists().getByTitle("Meeting Expenditures");

var meetingExpendituresQueryXml =
    "<View>" +
        "<Query>" +
            "<OrderBy>" +
                "<FieldRef Name='Month' Ascending='FALSE' />" +
            "</OrderBy>" +
        "</Query>" +
    "</View>";

var meetingExpendituresCamlQuery = new SP.CamlQuery();
meetingExpendituresCamlQuery.set_viewXml(meetingExpendituresQueryXml);

meetingExpendituresListItems = meetingExpendituresOList.getItems(meetingExpendituresCamlQuery);
clientContext.load(meetingExpendituresListItems);

so my question is how many max items will be retrieved? only 5000 items? or all items from the related list? Thanks

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

2 answers

Sort by: Most helpful
  1. Vergil-V 14,435 Reputation points Microsoft External Staff Moderator
    2026-06-07T13:27:28.6033333+00:00

    Hi john john Pter

    I would like to share some additional insight alongside the AI response. You may want to consider indexing your Month column to help SharePoint avoid performing a full scan before applying the filter. This can help reduce the chance of hitting errors such as “The number of items in this list exceeds the list view threshold.” 

    In addition, based on common approaches, many users combine paging methods with row limits, as mentioned in the AI response, to retrieve items in SharePoint. This allows you to retrieve items sequentially without reaching the 5000 item limit in a single request. 

    Reference:  

    If you are familiar with Power Automate, you may also find this discussion helpful for handling the 5000 items limit in flows: Solved: Best method to to get more than 5000 items from SharePoint Online in Flow 

    For Microsoft Graph API, you could consider using List items - Microsoft Graph v1.0 | Microsoft Learn. It does not return all items in one response, but it provides OData links that allow you to continue retrieving items in sequence until you reach the end of the list. 

    I hope this brings additional insight. 


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Was this answer helpful?


  2. AI answer

    2026-06-07T11:49:27.87+00:00

    SP.CamlQuery.createAllItemsQuery() creates a CAML query that returns all items in the list, not just 5,000.

    However, SharePoint list queries are still subject to list view thresholds and limits on the server. So while the query definition itself is “all items,” the actual number of items returned in one call can be constrained by SharePoint’s internal limits and any RowLimit you specify.

    To control how many items are returned per call, use the overload that takes a rowLimit parameter:

    public static Microsoft.SharePoint.Client.CamlQuery CreateAllItemsQuery(int rowLimit, params string[] viewFields);
    

    This lets the code page through items in batches (for example, 100, 500, etc.) instead of trying to load everything at once.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.