Hi,
I am Using the code below to retrieve multiple records using Web API. Code works fine with CRM 2016 (Api v8.0) but it is not working with Dynamics 365 (Api v8.2).
I am getting an error saying 'Invalid XML'. While debugging in Chrome, I can see the error message saying "Failed to load resource: the server responded with a status of 500 (Internal Server Error)".
Code:
var fetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" + "<entity name='contractdetail'>" + "<attribute name='contractid' />" + "<attribute name='title' />" + "<attribute name='contractdetailid' />" + "</entity>" + "</fetch>"; var uri = "/contractdetails?fetchXml=" + encodeURIComponent(fetchXml); var clientUrl = Xrm.Page.context.getClientUrl(); var webApiPath = "/api/data/v8.2"; uri = clientUrl + webApiPath + uri; var request = new XMLHttpRequest(); request.open("GET", encodeURI(uri), false); request.setRequestHeader("Accept", "application/json"); request.setRequestHeader("Content-Type", "application/json; charset=utf-8"); request.setRequestHeader("OData-MaxVersion", "4.0"); request.setRequestHeader("OData-Version", "4.0"); request.setRequestHeader("Prefer", "odata.include-annotations=\"OData.Community.Display.V1.FormattedValue\""); request.setRequestHeader("Prefer", "odata.maxpagesize=10"); request.onreadystatechange = function () { if (request.readyState === 4 /* complete */) { if (request.status === 200) { request.onreadystatechange = null; // avoid memory leaks var data = JSON.parse(request.response); CCS.IncidentForm.OnSuccessOfSetContractFromProduct(data, checkProductMarket); } else { var error = JSON.parse(request.response).error; CCS.IncidentForm.OnError(error); } } }; request.send();
Error:
Can anyone please suggest me what could be the issue.
Many Thanks
*This post is locked for comments