retrieve more than 5 K record

    public static EntityCollection paginationQuery (OrganizationServiceProxy _service, QueryExpression query)
        {
            int queryCount = 2500;
            int pageNumber = 1;
            int recordCount = 0;
            query.PageInfo = new PagingInfo();
            query.PageInfo.Count = queryCount;
            query.PageInfo.PageNumber = pageNumber;
            query.PageInfo.PagingCookie = null;
            EntityCollection fullResult = new EntityCollection();

            while (true)
            {
                // Retrieve the page.
                EntityCollection results = _service.RetrieveMultiple(query);
                
                if (results.Entities != null)
                {
                    // Retrieve all records from the result set.
                    foreach (var rec in results.Entities)
                    {
                        fullResult.Entities.Add(rec);
                        
                    }
                }

                // Check for more records, if it returns true.
                if (results.MoreRecords)
                {                    
                    // Increment the page number to retrieve the next page.
                    query.PageInfo.PageNumber++;
                    // Set the paging cookie to the paging cookie returned from current results.
                    query.PageInfo.PagingCookie = results.PagingCookie;
                }
                else
                {
                    return fullResult;
                    // If no more records are in the result nodes, exit the loop.
                    break;
                }
                
            }
            return fullResult;
        }

Commentaires

Posts les plus consultés de ce blog

CRM dynamics V9 wait Async web API to contiue code

How to connect to Crm Dynamics On Premis 2016 with Consol App

promise example