Skip to main content

Notifications

Announcements

No record found.

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

  • Verified answer
    ashlega Profile Picture
    ashlega 34,477 on at
    RE: Failed to load resource: the server responded with a status of 500 (Internal Server Error)

    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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,409 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans