Sdílet prostřednictvím


The number of search results is 5000 when setting the Count attribute to 20000 in Microsoft Dynamics CRM

This article provides a resolution for the issue that the number of search results that is returned is 5,000 even if you set the Count attribute to 20,000 in the FetchXml schema.

Applies to:   Microsoft Dynamics CRM 2011
Original KB number:   911510

Important

This article contains information about how to modify the registry. Make sure that you back up the registry before you modify it. Make sure that you know how to restore the registry if a problem occurs. For more information about how to back up, restore, and modify the registry, see How to back up and restore the registry in Windows.

Symptoms

You use the Count attribute in the FetchXml schema to create a query against the Microsoft Dynamics CRM database. Then, you set the Count attribute to 20,000. In this scenario, the number of search results that is returned is 5,000. Additionally, the SELECT statement in the SQL language is always SELECT TOP 5001 regardless of what is set for the Count attribute and for the Paging attribute.

Cause

This issue occurs when you use the FetchXml schema to retrieve a resulting search set and when the moreRecords attribute is set to 1. The value of 1 indicates that more than 5,000 records are available. In Microsoft Dynamics CRM, the Paging attribute has a page limit of 5,000.

Resolution

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure. However, they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.

To resolve this issue, use the Paging attribute to retrieve records. Then, use the moreRecords attribute in the resulting search set to determine whether the next page should be returned.

For example, the following code demonstrates how to resolve this issue.

moreRecords = true;
i = 0;
while(moreRecords)
{
get page i
if(result has more records)
i++
else
moreRecords = false
}

More information

Warning

Serious problems might occur if you modify the registry incorrectly by using Registry Editor or by using another method. These problems might require that you reinstall the operating system. Microsoft cannot guarantee that these problems can be solved. Modify the registry at your own risk.

To adjust the page limit to a value that is less than 5,000, add the MaxRowsPerPage DWORD Value to the registry. To do this, follow these steps:

  1. Select Start, select Run, type regedit in the Open box, and then select OK.

  2. Locate and then select the following registry subkey:

    HKEY_LOCAL_MACHINE\Software\Microsoft\MSCRM

  3. On the Edit menu, point to New, and then select DWORD Value.

  4. Type MaxRowsPerPage, and then press ENTER.

  5. Right-click MaxRowsPerPage, and then select Modify.

  6. Type a number that is less than or equal to 5,000 in the Value data box, and then select OK.

  7. On the File menu, select Exit.

To turn off the paging feature and then ignore the MaxRowsPerPage parameter of 5,000, add the TurnOffFetchThrottling DWORD Value to the registry. To do this, follow these steps:

Note

Performing these steps may cause performance issues on your computer.

  1. Select Start, select Run, type regedit in the Open box, and then select OK.

  2. Locate and then select the following registry subkey:

    HKEY_LOCAL_MACHINE\Software\Microsoft\MSCRM

  3. On the Edit menu, point to New, and then select DWORD Value.

  4. Type TurnOffFetchThrottling, and then press ENTER.

  5. Right-click TurnOffFetchThrottling, and then select Modify.

  6. Type a number other than 0 in the Value data box, and then select OK.

    Note

    Step 6 lets you retrieve the number of records specified in the Count attribute of your fetch statement.

  7. On the File menu, select Exit.