locked
Odata query not supporting $filter $stop $expand RRS feed

  • Question

  • Hi everyone,

    I am just trying to  call a odata query to uodate a attribute

     I get this error:The status always return me 400.Please Help

      responseText "{Query options $expand, $filter, $orderby, $inlinecount, $skip and $top cannot be applied to the requested resource.}" String

    Here ia a part of my code:

    //my odata request

      var oDataPath = ServerUrl + "/XRMServices/2011/OrganizationData.svc";
        var oData = oDataPath + "/AppointmentSet?$select=Category&$filter=ActivityId eq guid'" + appointmentid + "'";

     var req = new XMLHttpRequest();

                       req.open("POST", encodeURI(oData), false);
                        req.setRequestHeader("Accept", "application/json");
                        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
                        req.setRequestHeader("X-HTTP-Method", "MERGE");
                        req.onreadystatechange = function () {
                            if (this.readyState == 4 /* complete */) {
                                req.onreadystatechange = null;
                                if (this.status == 204 || this.status == 1223) {
                                    successCallback();
                                }
                                else {
                                    debugger;
                                   errorCallback(SDK.REST._errorHandler(this));
                                }
                            }
                        };

    Thanks

    Surbhi


    • Edited by Surbhi99 Thursday, March 19, 2015 8:10 AM
    Thursday, March 19, 2015 8:05 AM

All replies

  • Hi, 

       Use below code to resolve your error

    function Retrieve() {

                        var oDataPath = ServerUrl + "/XRMServices/2011/OrganizationData.svc";                       

                     var oData = oDataPath + "/AppointmentSet?$select=Category&$filter=ActivityId eq guid'" + appointmentid + "'";

            var retrieveReq = new XMLHttpRequest();

            //alert(Odata);

            retrieveReq.open("GET", oData, false);

            retrieveReq.setRequestHeader("Accept", "application/json");

            retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");

            retrieveReq.onreadystatechange = function () { retrieveReqCallBack(this); };

            retrieveReq.send();

        }


    function retrieveReqCallBack(retrieveReq) {

        if (retrieveReq.readyState == 4 /* complete */) {

            var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;

            

            var category= retrieved.results[0].Category;       

           

        }

    }




    • Edited by Gugan A Thursday, March 19, 2015 9:40 AM
    Thursday, March 19, 2015 9:07 AM
  • Hi i tried the code

    got this error

    The X-HTTP-Method header can only be used with POST requests at

     var retrieved = this.parent.JSON.parse(retrieveReq.responseText).d;

    Thursday, March 19, 2015 10:36 AM
  • Hi, 

    IF u have added

       req.setRequestHeader("X-HTTP-Method", "MERGE");

    line in your code delete that line. Because X-HTTP-Method can be used only for  Delete and Update requests

    if not post your updated code here.



    • Edited by Gugan A Thursday, March 19, 2015 10:46 AM
    Thursday, March 19, 2015 10:42 AM