Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Xrm.Web.retrieveMultipleRecords doesn't return nextLink

Posted on by 40

Hi Experts,

I am trying to retrieve records using Xrm.Web.retrieveMultipleRecords request with the help of fetchxml but the result doesn't return nextLink.

var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' count='1'>" +

"<entity name='contact'>" +
"<attribute name='fullname' />" +
"<attribute name='telephone1' />" +
"<attribute name='contactid' />" +
"<order attribute='fullname' descending='false' />" +
"<filter type='and'>" +
"<condition attribute='lastname' operator='like' value='u%' />" +
"</filter>" +
"</entity>" +
"</fetch>";

var retrieveRecord1 = Xrm.Web.retrieveMultipleRecords("contact", "?fetchXml=" + encodeURIComponent(fetchXml), 1);

I have 3 contact records which satisfies above fetchxml but still I don't get nextLink using fetchxml. 

*This post is locked for comments

  • bsd Profile Picture
    bsd 5 on at
    RE: Xrm.Web.retrieveMultipleRecords doesn't return nextLink

    Sorry, posted this on the wrong thread....

    I know this is an old thread, but I recently dug into the issue.  

    In global.ashx there is a function that incorrectly attempts to read the next link off the response (@odata.nextLink instead of @Microsoft.Dynamics.CRM.fetchxmlpagingcookie):

    XrmClientApi.WebApi.WebApiService.$l = function($p0, $p1, $p2, $p3, $p4, $p5) {
        var $v_0 = {};
        var $v_1 = $p2.responseText;
        switch ($p3) {
            case 0:
                if ($v_1.length > 0) {
                    $v_0 = JSON.parse($v_1);
                }
                $p5.resolve($v_0);
                break;
            case 2:
            case 3:
            case 4:
                var $v_2 = new XrmClientApi.WebApi.EntityReference(XrmClientApi.WebApi.WebApiParser.getGuidFromResponse($p2), $p4);
                $p5.resolve($v_2);
                break;
            case 1:
                var $v_3 = null;
                if ($v_1.length > 0) {
                    var $v_6 = JSON.parse($v_1);
                    if ($v_6) {
                        $v_3 = new XrmClientApi.WebApi.RetrieveMultipleResponse($v_6['value'], $v_6['@odata.nextLink']);
                    }
                }
                $p5.resolve($v_3);
                break;
            case 5:
                $p5.resolve(XrmClientApi.WebApi.WebApiService.$w($p2));
                break;
            case 6:
                var $v_4 = $p5;
                var $v_5 = XrmClientApi.WebApi.WebApiParser.parseBatchResponse($p2, $v_4);
                $p5.resolve($v_5);
                break;
        }
    }
    

    It's totally unsupported, but correcting this function makes the paging cookie return properly.  Run this before running the retrieve multiple and see that the next link does return and is usable:

            XrmClientApi.WebApi.WebApiService.$l = function ($p0, $p1, $p2, $p3, $p4, $p5) {
                var $v_0 = {};
                var $v_1 = $p2.responseText;
                switch ($p3) {
                    case 0:
                        if ($v_1.length > 0) {
                            $v_0 = JSON.parse($v_1);
                        }
                        $p5.resolve($v_0);
                        break;
                    case 2:
                    case 3:
                    case 4:
                        var $v_2 = new XrmClientApi.WebApi.EntityReference(XrmClientApi.WebApi.WebApiParser.getGuidFromResponse($p2), $p4);
                        $p5.resolve($v_2);
                        break;
                    case 1:
                        var $v_3 = null;
                        if ($v_1.length > 0) {
                            var $v_6 = JSON.parse($v_1);
                            if ($v_6) {
                                $v_3 = new XrmClientApi.WebApi.RetrieveMultipleResponse($v_6['value'],  $v_6['@Microsoft.Dynamics.CRM.fetchxmlpagingcookie']);
                            }
                        }
                        $p5.resolve($v_3);
                        break;
                    case 5:
                        $p5.resolve(XrmClientApi.WebApi.WebApiService.$w($p2));
                        break;
                    case 6:
                        var $v_4 = $p5;
                        var $v_5 = XrmClientApi.WebApi.WebApiParser.parseBatchResponse($p2, $v_4);
                        $p5.resolve($v_5);
                        break;
                }
            }
    
    
    
    

  • Vikasdugi Profile Picture
    Vikasdugi 10 on at
    RE: Xrm.Web.retrieveMultipleRecords doesn't return nextLink

    Hi Guido,

    We are facing the same issue with Xrm.Page.retrieveMultipleRecords using fetchxml where we get the nextLink value as undefined.
    We have more than 5000 account records in CRM but it give first page set of records and the nextLink value as undefined.
    We also try with adding maxPageSize parameter but still facing same issue. This issue come with fetchxml only not with the Odata query.

    please find screenshot below:

    4276.Untitled4.png

  • Suggested answer
    Guido Preite Profile Picture
    Guido Preite 54,081 Super User 2024 Season 1 on at
    RE: Xrm.Web.retrieveMultipleRecords doesn't return nextLink

    you need to remove count='1' from your fetchxml, otherwise the query will always return 1 record.

    you are already doing the paging with the third argument (maxPageSize) of your retrieveMultipleRecords

  • LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Xrm.Web.retrieveMultipleRecords doesn't return nextLink

    Hi partner,

    You could refer to this blog.

    balugajjala.wordpress.com/.../

    I saw that you set it to return only one record per page, so as you said there are 3 records exist, there should be the "nextLink" attribute. 

    So you could also debug your code and see what's the content of "result".

    BTW, why did you add "count = 1" in your fetchxml? This code means you will only get 1 record in your result. Remove it and try again.

    Hope it helps.

    Best Regards,

    Leo

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: Xrm.Web.retrieveMultipleRecords doesn't return nextLink

    Hi,

    I may be wrong but it looks like the Next Link is not supported when you use FetchXml. Unfortunatly it is not mentioned in amy documentation yet so you may want to check this with Microsoft Support directly.

    Hope this help.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans