Skip to main content

Notifications

Microsoft Dynamics 365 | Integration, Dataverse...
Unanswered

How i can to retrive all data in html javascript with this exemple of microsoft doc- retrieveMultipleRecords fetchXmlPagingCookie

Posted on by 10

i want to print on my html with grid the data retrieved , if you have some ideas how to parse this on table with pagination. 

Link:  retrieveMultipleRecords (référence de l’API client) dans les applications basées sur un modèle - Power Apps | Microsoft Docs

and code : 

function CreateXml(fetchXml, pagingCookie, page, count) {
var domParser = new DOMParser();
var xmlSerializer = new XMLSerializer();

var fetchXmlDocument = domParser.parseFromString(fetchXml, "text/xml");

if (page) {
fetchXmlDocument
.getElementsByTagName("fetch")[0]
.setAttribute("page", page.toString());
}

if (count) {
fetchXmlDocument
.getElementsByTagName("fetch")[0]
.setAttribute("count", count.toString());
}

if (pagingCookie) {
var cookieDoc = domParser.parseFromString(pagingCookie, "text/xml");
var innerPagingCookie = domParser.parseFromString(
decodeURIComponent(
decodeURIComponent(
cookieDoc
.getElementsByTagName("cookie")[0]
.getAttribute("pagingcookie")
)
),
"text/xml"
);
fetchXmlDocument
.getElementsByTagName("fetch")[0]
.setAttribute(
"paging-cookie",
xmlSerializer.serializeToString(innerPagingCookie)
);
}

return xmlSerializer.serializeToString(fetchXmlDocument);
}

function retrieveAllRecords(entityName, fetchXml, page, count, pagingCookie) {
if (!page) {
page = 0;
}

return retrievePage(entityName, fetchXml, page + 1, count, pagingCookie).then(
function success(pageResults) {
if (pageResults.fetchXmlPagingCookie) {
return retrieveAllRecords(
entityName,
fetchXml,
page + 1,
count,
pageResults.fetchXmlPagingCookie
).then(
function success(results) {
if (results) {
return pageResults.entities.concat(results);
}
},
function error(e) {
throw e;
}
);
} else {
return pageResults.entities;
}
},
function error(e) {
throw e;
}
);
}

function retrievePage(entityName, fetchXml, pageNumber, count, pagingCookie) {
var fetchXml =
"?fetchXml=" + CreateXml(fetchXml, pagingCookie, pageNumber, count);

return Xrm.WebApi.online.retrieveMultipleRecords(entityName, fetchXml).then(
function success(result) {
return result;
},
function error(e) {
throw e;
}
);
}

var count = 3;
var fetchXml =
'<fetch mapping="logical"><entity name="account"><attribute name="accountid"/><attribute name="name"/></entity></fetch>';

retrieveAllRecords("account", fetchXml, null, count, null).then(
function success(result) {
console.log(result);

// perform additional operations on retrieved records
},
function error(error) {
console.log(error.message);
// handle error conditions
}
);

  • crm dunamics 365 Profile Picture
    crm dunamics 365 10 on at
    RE: How i can to retrive all data in html javascript with this exemple of microsoft doc- retrieveMultipleRecords fetchXmlPagingCookie

    hi ,

    I'm trying to create a grid, I manage to retrieve the data, there is a response for to the request, but I can't  manipulate the data in order to display them in a table with pagination, in the console, pagingcookie returned me link and I retrieve all record, but in html I manage to display only the first page but how to do for all record and next pages.

    regards,

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: How i can to retrive all data in html javascript with this exemple of microsoft doc- retrieveMultipleRecords fetchXmlPagingCookie

    Hi crm dunamics 365,

    Could you tell us where are you stuck? Could not get next page data?

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans