locked
retrive more than 5000 records from crm 2011 using web service and c# RRS feed

  • Question

  • Hi All,

    I was unable to retrieve more than 500 records using web service, please suggest me how to retrieve more than 500 records using webservice


    Thanks in Advance Siva

    Tuesday, January 15, 2013 9:26 AM

Answers

  • Hi Sam,

    you can get more than 5000 records like that

      public List<Entity> GetAllAccount(IOrganizationService service)
            {
                int i = 0;
                List<Entity> AllAccount = new List<Entity>();
               
                try
                {
                    
                    _service = service;
                    int fetchCount = 5000;
                    int pageNumber = 1;
                    List<Guid> dicacc = new List<Guid>();
                    QueryExpression QE = new QueryExpression();
                    QE.ColumnSet = new ColumnSet(true);
                    QE.EntityName = "account";


                    QE.PageInfo = new PagingInfo();
                    QE.PageInfo.Count = fetchCount;
                    QE.PageInfo.PageNumber = pageNumber;
                    QE.PageInfo.PagingCookie = null;
                    while (true)
                    {
                        EntityCollection collections = _service.RetrieveMultiple(QE);
                        if (collections.Entities.Count > 0)
                        {
                        
                            foreach (Entity e in collections.Entities)
                            {
                                i++;

                                AllAccount.Add(e);
                              
                            }
                        }

                        if (collections.MoreRecords)
                        {
                            QE.PageInfo.PageNumber++;
                            QE.PageInfo.PagingCookie = collections.PagingCookie;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
               
                catch (Exception ex)
                {
                    
                }
                return AllAccount;
            }

    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise..:)

    Tuesday, January 15, 2013 1:25 PM
  • Hello,

    you need to use pageinfo,

    Check this


    Contact Me
    Follow me on Twitter
    My Facebook Page
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Tuesday, January 15, 2013 9:47 AM
    Moderator

All replies

  • Hello,

    you need to use pageinfo,

    Check this


    Contact Me
    Follow me on Twitter
    My Facebook Page
    Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.


    Tuesday, January 15, 2013 9:47 AM
    Moderator
  • Hi,

    Here you can find the description to increase the limit of the webservice response - by setting a registry value: http://www.interactivewebs.com/blog/index.php/server-tips/turn-off-microsoft-crm-2011-5000-limit-on-data-retrieval-via-sdk/

    Best regards,

    Andreas


    Andreas Buchinger
    Microsoft Dynamics Certified Technology Specialist
    MCPD: SharePoint Developer 2010

    Tuesday, January 15, 2013 11:36 AM
  • Hi Sam,

    you can get more than 5000 records like that

      public List<Entity> GetAllAccount(IOrganizationService service)
            {
                int i = 0;
                List<Entity> AllAccount = new List<Entity>();
               
                try
                {
                    
                    _service = service;
                    int fetchCount = 5000;
                    int pageNumber = 1;
                    List<Guid> dicacc = new List<Guid>();
                    QueryExpression QE = new QueryExpression();
                    QE.ColumnSet = new ColumnSet(true);
                    QE.EntityName = "account";


                    QE.PageInfo = new PagingInfo();
                    QE.PageInfo.Count = fetchCount;
                    QE.PageInfo.PageNumber = pageNumber;
                    QE.PageInfo.PagingCookie = null;
                    while (true)
                    {
                        EntityCollection collections = _service.RetrieveMultiple(QE);
                        if (collections.Entities.Count > 0)
                        {
                        
                            foreach (Entity e in collections.Entities)
                            {
                                i++;

                                AllAccount.Add(e);
                              
                            }
                        }

                        if (collections.MoreRecords)
                        {
                            QE.PageInfo.PageNumber++;
                            QE.PageInfo.PagingCookie = collections.PagingCookie;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
               
                catch (Exception ex)
                {
                    
                }
                return AllAccount;
            }

    Please don't forget to Vote and marked as answer If this post answers your question or was helpful, please click "Mark As Answer" on the post and "Mark as Helpful" Be wise..:)

    Tuesday, January 15, 2013 1:25 PM
  • Thanks for the tip.

    Helped me a lot.

    ------------------------ Alexandre Kohn

    Thursday, November 21, 2013 5:51 PM