MS CRM 2011 Fetchxml not working
-
Mittwoch, 10. August 2011 09:38
Hi ,
I am trying to fetch record using fetch xml in MS CRM 2011 and getting "Internal Server Error" error 500 . Below is the code i am using. Also mention responseText after the code . Could you please tell what is not correct in this .
var serverUrl="http://localhost/organization/XRMServices/2011/Organization.svc/web";var fetchquery = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
"<entity name='account'>" +
"<attribute name='name' /> " +
"<order attribute='name' descending='false' /> " +
"<filter type='and'>" +
"<condition attribute='accountid' operator='eq' value='{CA8D988C-4A96-E011-A9ED-00155D06EC29}' /> " +
"</filter>" +
"</entity>" +
"</fetch>";var requestMain = ""
requestMain += "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">";
requestMain += " <s:Body>";
requestMain += " <Execute xmlns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Services\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">";
requestMain += " <request i:type=\"a:RetrieveMultipleRequest\" xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">";
requestMain += " <a:Parameters xmlns:b=\"http://schemas.datacontract.org/2004/07/System.Collections.Generic\">";
requestMain += " <a:KeyValuePairOfstringanyType>";
requestMain += " <b:key>Query</b:key>";
requestMain += " <b:value i:type=\"a:FetchExpression\">";
requestMain += " <a:Query>"+fetchquery+"</a:Query>";
requestMain += " </b:value>";
requestMain += " </a:KeyValuePairOfstringanyType>";
requestMain += " </a:Parameters>";
requestMain += " <a:RequestId i:nil=\"true\" />";
requestMain += " <a:RequestName>RetrieveMultiple</a:RequestName>";
requestMain += " </request>";
requestMain += " </Execute>";
requestMain += " </s:Body>";
requestMain += "</s:Envelope>";
var req = new XMLHttpRequest();
req.open("POST",serverUrl, false)
// Responses will return XML. It isn't possible to return JSON.
req.setRequestHeader("Accept", "application/xml, text/xml, */*");
req.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
req.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute");
req.send(requestMain);Response text error message
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher">a:DeserializationFailed</faultcode><faultstring xml:lang="en-US">The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:request. The InnerException message was 'There was an error deserializing the object of type Microsoft.Xrm.Sdk.OrganizationRequest. End element 'Query' from namespace 'http://schemas.microsoft.com/xrm/2011/Contracts' expected. Found element 'fetch' from namespace 'http://schemas.microsoft.com/xrm/2011/Contracts/Services'. Line 1, position 641.'. Please see InnerException for more details.</faultstring></s:Fault></s:Body></s:Envelope>BR,
Saurabh
Saurabh
Alle Antworten
-
Mittwoch, 10. August 2011 14:57Moderator
This looks like a basic query. I am not sure what is wrong, but I have gotten this to work before and blogged about it.
http://mileyja.blogspot.com/2011/06/use-fetchxml-queries-in-jscript-and-net.html
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Als Antwort vorgeschlagen Jamie MileyMVP, Moderator Freitag, 29. Juni 2012 14:38
-
Freitag, 29. Juni 2012 14:38ModeratorDid that help you at all?
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!