Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Pagination in Webapi retrive call

(0) ShareShare
ReportReport
Posted on by 161

Hi team,

i have one code to retrive child contacts count as below but i want to implement the paging and want to limit record set to 50 for every call and it should not fetch all 5000 records in a single call.

i am new to webapi so need some assistance on this kinldy suggest how could i embed that concept into this code

function retrieveentityCollection() {

   debugger;

   var entity="contacts";

   var Id = Xrm.Page.data.entity.getId().substring(1, 37);

   var options ="?$select=firstname&$filter=_accountid_value eq " + Id + "&$count=true";

   var serverURL = Xrm.Page.context.getClientUrl();

   var Query = entity + options;

   var req = new XMLHttpRequest();

   req.open("GET", serverURL + "/api/data/v9.0/" + Query, true);

   req.setRequestHeader("Accept", "application/json");

   req.setRequestHeader("Content-Type", "application/json; charset=utf-8");

   req.setRequestHeader("OData-MaxVersion", "4.0");

   req.setRequestHeader("OData-Version", "4.0");

   req.onreadystatechange = function() {

       if (this.readyState == 4 /* complete */ ) {

           req.onreadystatechange = null;

           if (this.status == 200) {

               var data = JSON.parse(this.response);

               if(data['@odata.count']!=null)

                   Xrm.Page.getAttribute("numberofemployees").setValue(data['@odata.count']);

               alert(data['@odata.count']);

               for (var i = 0; i < data.value.length; i++) {

                   var name = data.value[i]["firstname"];

                   Xrm.Utility.alertDialog(name);

               }

           }

           else {

               var error = JSON.parse(this.response).error;

               Xrm.Utility.alertDialog(error.message);

           }

       }

   };

   req.send();

}

*This post is locked for comments

  • Suggested answer
    Vipin J Profile Picture
    Vipin J 1,583 on at
    RE: Pagination in Webapi retrive call

    Here are complete post for pagination in dynamic CRM using javascript

    [View:https://vjcity.blogspot.com/2019/11/paging-fetchxml-queries-in-dynamic-crm.html:750:50]

    [View:https://vjcity.blogspot.com/2019/11/paging-in-dynamic-365-crm-using.html:750:50]

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Pagination in Webapi retrive call

    Take a look at the following blog post of using FetchXml with Pagination.

    You can try with top and skip or use the logic in the post.

    www.inogic.com/.../execute-fetchxml-using-web-api-in-dynamics-crm-2016

    Hope this helps.

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Pagination in Webapi retrive call

    Hi,

    Refer the links below.

    knpuniversity.com/.../pagination

    developer.wordpress.org/.../pagination

    Hope this helps.

  • Nagaraj M Profile Picture
    Nagaraj M 161 on at
    RE: Pagination in Webapi retrive call

    actually i want to fetch more than 5000 records and i am passing fetchxml as query to execute so still is possible to solve this with skip and top together?

  • Nagaraj M Profile Picture
    Nagaraj M 161 on at
    RE: Pagination in Webapi retrive call

    Thanks Gopinath I am not able to reach to the url may be some network or server unavailable issue it seems,

    Can you provide some more links

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Pagination in Webapi retrive call

    Hi Nagaraj,

    Please refer the link below.

    developer.wordpress.org/.../pagination

    Hope this helps.

  • Suggested answer
    Aric Levin Profile Picture
    Aric Levin 30,188 on at
    RE: Pagination in Webapi retrive call

    Why not use skip and top together:

    var skipRecords = (pageNumber-1) * 10;

    var options ="?$select=firstname&$filter=_accountid_value eq " + Id + "&$skip=" + skipRecords + "&$top=10

    Hope this helps.

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,445 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans