Search code examples
dynamics-crmcrmfetchxml

CRM FetchXML fetch more than 5000 records


I have more than 5000 records that I want to fetch with this query, but I get cookie with null value every time. I realized that linked entity is the problem here, because when I remove it I get the cookie every time.

<fetch version="1.0" mapping="logical" distinct="true" page="1" count="2000" >
    <entity name="listmember" >
        <link-entity name="contact" from="contactid" to="entityid" alias="c" >
            <attribute name="contactid" />
            <attribute name="telephone1" />
            <link-entity name="phonecall" from="ic_customer" to="contactid" alias="pc" link-type="outer"  distinct="true">
                <attribute name="activityid" />
                <filter type="and" >
                    <filter type="or" >
                        <condition attribute="statuscode" operator="eq" value="1" />
                        <condition attribute="ic_end" operator="on-or-after" value="2016-11-12" />
                    </filter>
                </filter>
            </link-entity>
            <filter type="and" >
                <condition attribute="statecode" operator="eq" value="0" />
                <condition attribute="telephone1" operator="not-null" />
                <condition attribute="donotphone" operator="eq" value="0" />
            </filter>
        </link-entity>
        <filter type="and" >
            <condition attribute="listid" operator="in" >
                <value>
                    {f89087ef-7017-e611-80e3-5065f38a3951}
                </value>
            </condition>
            <condition entityname="pc" attribute="activityid" operator="null" />
        </filter>
    </entity>
</fetch>

Anybody knows how to get paging cookie with this request?


Solution

  • Solution for this particular problem is that you need to specify ID column on your root entity. In this example you need to add listmemberid attribute to root listmember entity.

    <fetch version="1.0" mapping="logical" distinct="true" page="1" count="2000" >
        <entity name="listmember" >
            <attribute name="listmemberid" />
            <link-entity name="contact" from="contactid" to="entityid" alias="c" >
                <attribute name="contactid" />
                <attribute name="telephone1" />
                <link-entity name="phonecall" from="ic_customer" to="contactid" alias="pc" link-type="outer"  distinct="true">
                    <attribute name="activityid" />
                    <filter type="and" >
                        <filter type="or" >
                            <condition attribute="statuscode" operator="eq" value="1" />
                            <condition attribute="ic_end" operator="on-or-after" value="2016-11-12" />
                        </filter>
                    </filter>
                </link-entity>
                <filter type="and" >
                    <condition attribute="statecode" operator="eq" value="0" />
                    <condition attribute="telephone1" operator="not-null" />
                    <condition attribute="donotphone" operator="eq" value="0" />
                </filter>
            </link-entity>
            <filter type="and" >
                <condition attribute="listid" operator="in" >
                    <value>
                        {f89087ef-7017-e611-80e3-5065f38a3951}
                    </value>
                </condition>
                <condition entityname="pc" attribute="activityid" operator="null" />
            </filter>
        </entity>
    </fetch>