I'm building a web-ressource for Dynamics CRM (8.2). When I try to fetch data with fetchXml like this, everything is fine:
<fetch mapping="logical" count="3" >
<entity name="product" >
<attribute name="name" />
<attribute name="productnumber" />
</entity>
</fetch>
but if i add the 'page' parameter, like in the next code, i get Invalid XML.
<fetch mapping="logical" count="3" page="1" >
<entity name="product" >
<attribute name="name" />
<attribute name="productnumber" />
</entity>
</fetch>
I tested the fetch with the FetchXml Tester from XrmToolBox. There it works fine. What did I do wrong?
I tried to do the request with the npm package dynamics-web-api (https://www.npmjs.com/package/dynamics-web-api) and with XMLHttpRequest. Both worked like discribed above.
The Error-Message is this: (sorry for the formatting)
{
"error":{
"code":"",
"message":"Invalid XML.",
"innererror":{
"message":"Invalid XML.",
"type":"System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
"stacktrace":" at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.RetrieveMultiple(QueryBase query, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode)
at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.RetrieveMultiple(QueryBase query)
at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.ExecuteQueryForEntitySet(CrmODataExecutionContext context, String entitySetName, CustomQueryOptions queryOptions, String fetchXml)
at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityCollection(CrmODataExecutionContext context, String entityCollectionName, String castedEntityName, ODataQueryOptions queryOptions)
at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
**Edit**
My error were somewhere in the formatting of the fetch-string. I used:
const query = encodeURI(connectionString + "?fetchXml=" + encodeURI(xmlString));
the correct code is:
const query = encodeURI(connectionString) + "?fetchXml=" + encodeURI(xmlString);
Ty AnkUser for your example. It helped me much.