问题
I'm having a small issue with Dynamics CRM 2016 and fetchXml. In the CRM I have around 35K users. Since it seems Dynamics is limited to retrieve a maximum of 5000 elements per round, I needed to use the pagingCookie feature to retrieve the second page and so on. For example, to retrieve the second page of these records (from user 5001 to 10000) I had to retrieve first the users from 1 to 5000, obtain the paging cookie and relaunch the process with this cookie.
My question is: This requires getting a total of 10000 users while maybe I'm just interested in getting the second page, not the first one. Is there any direct way to get the second page of results without the pagingCookie?
Thank you
回答1:
Hi to get all your result you need to increase the number of page after each call to the crm and add to a list. I don't know what is your language you are programing but I give you a example in .net and I tested and was working. If you need in javascript is the same way.
public IEnumerable<Account> GetAllClients()
{
List<Account> listAccounts = new List<Account>();
int pageIndex = 1;
int pageSize = 1000;
while (true)
{
// FETCH CLIENTES
var Fetch = "<fetch version='1.0' page='" + pageIndex + "' count='" + pageSize + "' output-format='xml-platform' mapping='logical' distinct='true'>";
Fetch += "<entity name='account'>";
//Attributes
Fetch += "<attribute name='accountid' />";
Fetch += "<attribute name='name' />";
Fetch += "<attribute name='accountnumber' />";
Fetch += "<attribute name='accountid' />";
Fetch += "<order attribute='name' descending='false' />";
Fetch += "</entity>";
Fetch += "</fetch>";
EntityCollection resultClient = this.crmService.RetrieveMultiple(new FetchExpression(Fetch));
foreach (Account c in resultClient.Entities)
{
listAccounts.Add(c);
}
if (resultClient.MoreRecords)
{
// Increment the page number to retrieve the next page.
pageIndex++;
}
else
{
// If no more records in the result nodes, exit the loop.
break;
}
}
return listAccounts;
}
Cheers
来源:https://stackoverflow.com/questions/37159131/dynamics-crm-how-to-get-the-second-page-of-a-fetchxml-query-beyond-the-5000-el