Now I am using angular to develop a report, I need to retrieve more than 5000 data one time, and for some reason, I have to use fetch xml to retrieve data. The first fetch is successful, but the 2nd fetch is failed. Below is the code and error message.
retrieveMRecords(type: string, xml: string) {
let optionsString;
let pageNumber = 1;
let pageCount = 10;
if (xml) {
optionsString = this.createXML(xml, null, 1, 10);
}
let httpHeaders1 = new Headers({
'Content-Type': 'application/json; charset=utf-8',
'Accept': 'application/json',
'OData-MaxVersion': '4.0',
'OData-Version': '4.0',
'Prefer': 'odata.include-annotations=Microsoft.Dynamics.CRM.fetchxmlpagingcookie'
});
let httpOptions1 = new RequestOptions({ headers: httpHeaders1 });
// let queryLink = this.getODataPath() + type + encodeURI(optionsString);
return this.retriveOneTime(type, optionsString, httpOptions1, null, xml, pageNumber, pageCount);
}
createXML(xml: string, pagingCookie: string, page: number, count: number) {
xml = xml.replace('{pagecount}', count.toString()).replace('{pagenumber}', page.toString());
if (pagingCookie) {
xml = xml.replace('{paging-cookie}', 'paging-cookie=' + pagingCookie);
} else {
xml = xml.replace('"{paging-cookie}"', '');
}
return xml;
}
retriveOneTime(type: string,
queryLink: string,
httpOptions: RequestOptions,
result: any,
xml: string,
pageNumber: number,
pagecount: number) {
let link = this.getODataPath() + type + '?' + encodeURI(queryLink);
return this.http.get(link, httpOptions)
.mergeMap(res => {
let resValue = this.extractData(res);
if (!result) {
result = resValue;
} else {
result = Observable.merge(result, resValue);
}
let body = res.json();
if (body) {
let pagingcookie = body['@Microsoft.Dynamics.CRM.fetchxmlpagingcookie'];
if (pagingcookie) {
let cookie = pagingcookie.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
if (cookie) {
let nextLink = this.createXML(xml, decodeURI(cookie), pageNumber++, pagecount);
if (nextLink) {
return this.retriveOneTime(type, nextLink, httpOptions, result, xml, pageNumber++, pagecount);
}
}
}
}
return result;
});
}
-------------------------------------------------------------------
{
"error":{
"code":"","message":"No Other Query options supported when SavedQuery or UserQuery or FetchXml option is provided","innererror":{
"message":"No Other Query options supported when SavedQuery or UserQuery or FetchXml option is provided","type":"Microsoft.Crm.CrmException","stacktrace":" at Microsoft.Crm.CrmException.Assert(Boolean condition, String message)\r\n at Microsoft.Crm.Extensibility.OData.Extensions.EdmExtensions.IsCustomQueryOptionPresent(HttpRequestMessage request)\r\n at Microsoft.Crm.Extensibility.OData.EntityController.GetEntitySet(String entitySetName)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}
-------------------------------------------------------------
Is there anyone knows what the problem is?
*This post is locked for comments