Hello,
function getAppointment() { var appointmentQueryValue = ""; appointmentQueryValue += '<entity name="appointment">'; appointmentQueryValue += '<attribute name="subject" />'; appointmentQueryValue += '</entity>'; var finalData = []; geRecordsFetchXML("appointments", appointmentQueryValue, finalData); } function geRecordsFetchXML(entityName, ODataUrl, finalData) { var fetchQuery = ''; var req = new XMLHttpRequest(); fetchQuery = ['<fetch mapping="logical" output-format="xml-platform" version="1.0">', ODataUrl, '</fetch>'].join(''); fetchQuery = escape(fetchQuery); req.open('GET', serverUrl + '/api/data/v8.0/' + entityName + '?fetchXml=' + fetchQuery, true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Prefer", "odata.include-annotations=*"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { var data = JSON.parse(this.response); if (data != null && data.value != null) { for (var i = 0; i < data.value.length; i++) { finalData.push(data.value[i]); } } if (data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] != undefined && data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] != null && data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] != "") { //next link } else { callbackFetchXml(finalData); //my all records } } else { var error = JSON.parse(this.response).error; alert("error " + error.message); } } }; req.send(); }
*This post is locked for comments
I had same challange, using fetchxml with webapi, and finally found the solution:
Assuming you have a response from your first request, with a blank paging-cookie, and if more pages are found, you can get the paging cookie from "@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"
remember to add the this http header to get that cat:
headers = headers.append("Prefer", "odata.include-annotations=\"*\"");
and below the type-/javascript to extract the pagingcookie and add it to the next fetchxml:
var fragment = "";
var pageCookie = response["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] as string;
if (pageCookie != null && pageCookie != '') {
let pageCookieMatch = /(?<=pagingcookie=['"])[a-z,A-Z,0-9,%-_.~]+/g;
fragment = decodeURIComponent(decodeURIComponent(pageCookie.match(this.pageCookieMatch)[0]));
fragment = fragment.replace(/&/g,"&").replace(/</g, "<").replace(/>/g, ">").replace(/\"/g, """);
}
let fetchxml = "<fetchxml mapping='logical' paging-cookie='"+fragment+"' page='"+ nextpage +"' count='"+pagesize+"'>...</fetchxml>
You can have a look below thread -
Hay Chhaya,
As per the authors post in the comments the issues is occurring due to a plugin on the same entity, from the link(www.inogic.com/.../execute-fetchxml-using-web-api-in-dynamics-crm-2016) share by Goutam.
Copy of post
Recently, we also came across the same kind of issue, where when we tried to retrieve more than 5K records of Contact Entity, it returned the same paging cookie all the time. Due to this, it retrieved the same records again and again and the process went into a recursive loop that never ended. As we worked on this, we found that it occurred because we have created a field on the Contact Entity and the value in this field gets populated by the plug-in. We have registered the plugin on the Retrieve Multiple message which reads value from other Entity and sets into this field that is shown to the user, but we do not save the value of this field in database. This field is like a virtual field, which may be the reason that it gives the same paging cookie each time. If we remove this field from fetchxml and execute using Web API, it starts working.
Do you have any such fields in your fetch?
hi
I am getting the same issue with the fetchxml query, it is going in recursive loop.
Thanks & regards
Subhash Mahato
Hi Goutam,
I get same page cookies in FetchMore() function, So it is going in recursive loop.
Please help me to solve this issue.
fetchMore: function (originalFetch, entitySetName, retrieveUsingFetchSucess, errorCallback, pageCookies, pageNumber, entityObj) { //pageCookies }
Thanks Goutam!
I have already tried that solution. but It gives me same page number in fetchMore() function.
Can you please tell me that why It gives me same Page Number?
Goutam provided a link to a blog post that answers this in your duplicate question at community.dynamics.com/.../306157
Hi,
Please have a look below reference -
www.inogic.com/.../execute-fetchxml-using-web-api-in-dynamics-crm-2016
function getAppointment() { var appointmentQueryValue = ""; appointmentQueryValue += '<entity name="appointment">'; appointmentQueryValue += '<attribute name="subject" />'; appointmentQueryValue += '</entity>'; var finalData = []; geRecordsFetchXML("appointments", appointmentQueryValue, finalData); } function geRecordsFetchXML(entityName, ODataUrl, finalData) { var fetchQuery = ''; var req = new XMLHttpRequest(); fetchQuery = ['<fetch mapping="logical" output-format="xml-platform" version="1.0">', ODataUrl, '</fetch>'].join(''); fetchQuery = escape(fetchQuery); req.open('GET', serverUrl + '/api/data/v8.0/' + entityName + '?fetchXml=' + fetchQuery, true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Prefer", "odata.include-annotations=*"); req.onreadystatechange = function () { if (this.readyState == 4) { req.onreadystatechange = null; if (this.status == 200) { var data = JSON.parse(this.response); if (data != null && data.value != null) { for (var i = 0; i < data.value.length; i++) { finalData.push(data.value[i]); } } if (data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] != undefined && data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] != null && data["@Microsoft.Dynamics.CRM.fetchxmlpagingcookie"] != "") { //next link } else { callbackFetchXml(finalData); //my all records } } else { var error = JSON.parse(this.response).error; alert("error " + error.message); } } }; req.send(); }
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156