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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Failed to load resource: the server responded with a status of 500 (Internal Server Error)

(0) ShareShare
ReportReport
Posted on by 272
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:

5415.Capture4.JPG

Can anyone please suggest me what could be the issue. 

Many Thanks

*This post is locked for comments

I have the same question (0)
  • Verified answer
    ashlega Profile Picture
    34,477 on at

    Hi,

     see if not using encodeURIComponent will help:

     var uri = "/contractdetails?fetchXml=" + fetchXml;

     Worked for me at least:)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans