web
You’re offline. This is a read only version of the page.
close
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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans