web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

Client Side Web Api Paging ,How to Find Still more pages are exist or not.

(0) ShareShare
ReportReport
Posted on by 244

Hello All,

I am  follow the simpleSPA application with adal.js ,now i am able retrieve the record ,using following code given below, 

My Problem ,I don't know still records are exists in entity ,to retrieve using paging ... I want all these values in grid with pages ...when ever clicks on page 2 or 3 or 4 ... i want retrieve those page records,is it possible ? if not what is the way first ,next ,previous, last  at-least these 4 options are possible .

function retrieveNextPage() {
        authContext.acquireToken(organizationURI, retrieveNextPage1);
    }
    function retrieveNextPage1(error, token)
    {
        var fetchxml = "<fetch mapping='logical' page='2' count='10' pagingcookie='%253ccookie%2520page%253d%25221%2522%253e%253caccountid%2520last%253d%2522%257bB8A19CDD-88DF-E311-B8E5-6C3BE5A8B200%257d%2522%2520first%253d%2522%257b475B158C-541C-E511-80D3-3863BB347BA8%257d%2522%2520%252f%253e%253c%252fcookie%253e'>" +
  "  <entity name='account' >" +
  "    <attribute name='emailaddress1' />" +
  "    <attribute name='address1_city' />" +
  "    <attribute name='accountid' />" +
  "    <attribute name='parentaccountid' />" +
  "    <attribute name='address1_composite' />" +
  "    <attribute name='name' />" +
  "  </entity>" +
  "</fetch>";
 
 
        var req = new XMLHttpRequest()
        req.open("GET", encodeURI(organizationURI + "/api/data/v9.0/accounts?fetchXml=" + fetchxml), true);
        //Set Bearer token
        req.setRequestHeader("Authorization", "Bearer " + token);
        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.setRequestHeader("Prefer", "odata.include-annotations=*");
        req.onreadystatechange = function () {
            if (this.readyState == 4 /* complete */) {
                req.onreadystatechange = null;
                if (this.status == 200) {
                    var accounts = JSON.parse(this.response).value;
                    var temp = JSON.parse(this.response);
                    temp["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"];
                    var entityObj = [];
                    var pagingInfo = null;
                    debugger;
 
                    //Check if results contains cookies
                    //if yes then retrieve next set of records
                    if (temp["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] != null) {
 
                        document.getElementById("next").style.display = "block";
                        document.getElementById("nxtPage").textContent = "";
                        document.getElementById("nxtPage").textContent = temp["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"];
                    }
                    renderAccounts(accounts);
                }
                else {
                    var error = JSON.parse(this.response).error;
                    console.log(error.message);
                    errorMessage.textContent = error.message;
                }
            }
        };
        req.send();
 
    }

Pages-Count.png

Thanks ,

In Advance. 

https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/walkthrough-registering-configuring-simplespa-application-adal-js

I have the same question (0)
  • Verified answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Hi Sairam,

    You can use fetch xml property "returntotalrecordcount" to true which will return you the count in ["@Microsoft.Dynamics.CRM.totalrecordcount"].

    Hope this helps.

  • Suggested answer
    RaviKashyap Profile Picture
    55,410 Moderator on at

    Also, I would suggest you to download and use CRM Rest Builder to build the WEB API request. This is the easiest way to build the query as well as execute it and see the results. You can examine the query results as well.

    github.com/.../releases

    www.toplinestrategies.com/.../crm-rest-builder-useful-tool-working-crm-2016’s-web-api

    Hope this helps.

  • Sairam89 Profile Picture
    244 on at

    Thanks Ravi,

    It is correct answer.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Dynamics 365 general

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans