Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to get more than 5000 records using FetchXML query?

(0) ShareShare
ReportReport
Posted on by 515

Hello,

I need to show more than 5000 record to my Portal website. I am using FetchXML query to get records from my Dynamics 365 instance to Dynamics 365 Portal website. but it can't fetch more than 5000 records in single FetchXML query.

Some article on the web states that it is limitation of FetchXML query. see below : 

https://community.dynamics.com/enterprise/b/dynamics365apps/archive/2017/02/28/quick-reference-dynamics-365-online-limitations

http://www.kingswaysoft.com/blog/2013/06/18/Limitations-with-CRM-FetchXML

one of the solution to overcome this problem is to use FetchXML with paging cookie, see here - https://msdn.microsoft.com/en-us/library/gg328046.aspx

but I can not use this as solution as I can't use c# code in Portal website development, is there any way to enhance limit of FetchXML query or any manual way to get record from dynamics 365 instance to dynamics portal?

Thanks,

Ashish

*This post is locked for comments

  • Suggested answer
    CRMJetty Profile Picture
    3,508 on at
    RE: How to get more than 5000 records using FetchXML query?

    Hello Ashish,

    Pls read this article,

    https://promx.net/en/2020/02/working-with-more-than-5000-records-in-dynamics-365/#

    https://pravinpawarweb.wordpress.com/2019/06/08/plugin-code-to-retrieve-more-than-5000-records-using-fetch-xml-in-crm/

    I hope it helps,

    Thanks.

    Please mark as verified if the answer is helpful. Welcome to join hot discussions in Dynamics 365

  • Suggested answer
    Prudvihub Profile Picture
    65 on at
    RE: How to get more than 5000 records using FetchXML query?

    Take a look into

    prudvihub.blogspot.com/.../how-to-retrive-more-than-5k-records-in.html

  • Suggested answer
    Prudvihub Profile Picture
    65 on at
    RE: How to get more than 5000 records using FetchXML query?

    Look into this

    prudvihub.blogspot.com/.../how-to-retrive-more-than-5k-records-in.html

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at
    RE: How to get more than 5000 records using FetchXML query?

    Here is a complete JavaScript code which help you understand pagination when using Select clause or Fetch XML

    Refer below links.

    [View:https://vjcity.blogspot.com/2019/11/paging-fetchxml-queries-in-dynamic-crm.html:750:50]

    [View:https://vjcity.blogspot.com/2019/11/paging-in-dynamic-365-crm-using.html:750:50]

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: How to get more than 5000 records using FetchXML query?

    Hi Ashish,

    Below is the code by which you can retrieve more that 5000 records, create a console application and test it

    static void Main(string[] args)

           {  

     var fetch = "<fetch {0}>" +

                               "    <entity name='new_zipcode' >" +

                               "        <attribute name='new_zipcodeid' />" +

                               "        <attribute name='new_name' />" +

                               "    </entity>" +

                               "</fetch>";

                       List<Entity> accountCol = RetrieveAllRecords(_serviceProxy, fetch);

    int count = accountCol.Count / 1000;

                       for (int i = 0; i < count; i++)

                       {

                           var query = from p in accountCol.Skip(i * 1000).Take(1000)

                                       select p;

                           // Create an ExecuteMultipleRequest object.

                           var multipleRequest = new ExecuteMultipleRequest()

                           {

                               // Assign settings that define execution behavior: continue on error, return responses.

                               Settings = new ExecuteMultipleSettings()

                               {

                                  ContinueOnError = false,

                                   ReturnResponses = true

                               },

                               // Create an empty organization request collection.

                               Requests = new OrganizationRequestCollection()

                           };

                           // Add a UpdateRequest for each entity to the request collection.

                           foreach (var entity in query)

                           {

                               entity.Attributes["new_name"] = "testnew";

                               UpdateRequest updateRequest = new UpdateRequest { Target = entity };

                              multipleRequest.Requests.Add(updateRequest);

                          }

                           // Execute all the requests in the request collection using a single web method call.

                           ExecuteMultipleResponse multipleResponse = (ExecuteMultipleResponse)_serviceProxy.Execute(multipleRequest);

                       }

    }

    public static List<Entity> RetrieveAllRecords(IOrganizationService service, string fetch)

           {

               var moreRecords = false;

               int page = 1;

               var cookie = string.Empty;

               List<Entity> Entities = new List<Entity>();

               do

               {

                   var xml = string.Format(fetch, cookie);

                   var collection = service.RetrieveMultiple(new FetchExpression(xml));

                   if (collection.Entities.Count >= 0)

                       Entities.AddRange(collection.Entities);

                   moreRecords = collection.MoreRecords;

                   if (moreRecords)

                   {

                       page++;

                       cookie = string.Format("paging-cookie='{0}' page='{1}'", System.Security.SecurityElement.Escape(collection.PagingCookie), page);

                   }

               } while (moreRecords);

               return Entities;

           }

    Thanks,

    Shahbaaz

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at
    RE: How to get more than 5000 records using FetchXML query?

    Hi Ashish,

    There isn't seem to be any way around this. You can check the below post on the same which suggests that MS Support can increate if requested but again not confirmed if it has been increased for anybody.

    community.dynamics.com/.../221006

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans