Dynamics CRM-如何获取fetchXml查询的第二页(超过5000个元素)? [英] Dynamics CRM - How to get the second page of a fetchXml query beyond the 5000 elements?

查看:360
本文介绍了Dynamics CRM-如何获取fetchXml查询的第二页(超过5000个元素)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用Dynamics CRM 2016和fetchXml时遇到一个小问题。在CRM中,我大约有35K用户。由于Dynamics似乎限制为每轮最多检索5000个元素,因此我需要使用pagesCookie功能来检索第二个页面,依此类推。例如,要检索这些记录的第二页(从用户5001到10000),我必须首先从1到5000检索用户,获取分页cookie并使用此cookie重新启动该过程。

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.

我的问题是:这需要总共10000个用户,而也许我只是对获取第二页感兴趣,而不是第一页。是否有任何直接的方法可以在不使用PageCookie的情况下获得第二页的结果?

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?

谢谢

推荐答案

要获得所有结果,您需要在每次调用crm之后增加页数并添加到列表中。我不知道您使用的是哪种语言,但是我在.net中举了一个例子,我已经测试过并且正在工作。

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;
        }

干杯

这篇关于Dynamics CRM-如何获取fetchXml查询的第二页(超过5000个元素)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆