When you’re working with Dynamics 365, you may have encountered a limitation when it comes to retrieving records. The maximum number of records that can be retrieved in a single query is 5.000. This can be a problem if you need to retrieve a large number of records, such as for a data migration or integration project.
In one of my previous posts, I have demonstrated to do with QueryExpression. To see that post click here. This post will be about retrieveing more than 5000 records by using FetchXML.
Retrieving more than 5000 records using FetchXML in Dynamics 365 involves using the “paging cookie” and the page option in the FetchXML query, which allows you to retrieve a specific set of records and then move to the next set of records until all records have been retrieved.
Here’s an example of how to use the paging cookie option in a FetchXML query:
In this example, the count
attribute is not used so the default record count per page will be 5.000, which is the maximum number of records that can be retrieved in a single query. The PagingCookie attribute contains a cookie that specifies the page number (in this case, page 2) and the first and last record IDs in the set.
To retrieve the next set of records, you would simply increment the page number in the paging cookie and run the query again. This process can be repeated until all records have been retrieved.