Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Error: No Other Query options supported when SavedQuery or UserQuery or FetchXml option is provided

Posted on by Microsoft Employee

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, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
            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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans