您只能使用抓取XML一次取回5000條記錄。
爲了獲得更多的記錄,你必須使用尋呼的cookie,在這裏看到:
Sample: Use FetchXML with a paging cookie
代碼的相關位:
// Define the fetch attributes.
// Set the number of records per page to retrieve.
int fetchCount = 3;
// Initialize the page number.
int pageNumber = 1;
// Specify the current paging cookie. For retrieving the first page,
// pagingCookie should be null.
string pagingCookie = null;
主循環修改,因爲樣本似乎沒有更新分頁Cookie:
while (true)
{
// Build fetchXml string with the placeholders.
string xml = CreateXml(fetchXml, pagingCookie, pageNumber, fetchCount);
FetchExpression expression = new FetchExpression(xml);
var results = proxy.RetrieveMultiple(expression);
// * Build up results here *
// Check for morerecords, if it returns 1.
if (results.MoreRecords)
{
// Increment the page number to retrieve the next page.
pageNumber++;
pagingCookie = results.PagingCookie;
}
else
{
// If no more records in the result nodes, exit the loop.
break;
}
}
我個人傾向於使用LINQ而不是FetchXML,但值得注意的是Lasse V. Karlsen所說的,如果您向用戶展示這些信息,您可能想要進行某種分頁(在FetchXML或LINQ中)
來源
2014-11-05 10:59:51
Joe
你爲什麼要查詢這麼多記錄?當然你不會向用戶展示超過5000行來查看/選擇? – 2014-11-05 11:01:18
當您想從CRM中以編程方式將數據下載到自定義應用程序的數據庫中時,可能會出現這種情況。 – PhantomReference 2016-05-11 14:18:15