locked
Javascript ODATA Not working RRS feed

  • Question

  • I am executing user saved query using OData in javascript to retrieve usersavedquery GUID but i am facing error "executeUserQuery is not defined"

    Kindly suggest what is the issue code.

    function executeUserQuery() {
    debugger;
    var clientUrl = Xrm.Page.context.getClientUrl();
    var req = new XMLHttpRequest();
    req.open("GET", encodeURI(clientUrl + "/api/data/v8.0/userqueries?$select=name,userqueryid&$filter=name eq 'Fourth Coffee Won Opportunities'", true);
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.onreadystatechange = function () {
    if (this.readyState == 4 /* complete */) {
    req.onreadystatechange = null;
    if (this.status == 200) {
    var data = JSON.parse(this.response);
    var dat = data.value;
    alert(dat);
    }
    else {
    var error = JSON.parse(this.response).error;
    alert(error.message);
    }
    }
    };
    req.send();
    }

    Monday, November 21, 2016 1:52 PM

All replies

  • Try CRMRESTBUILDER from codeplex, also, what version of CRM are you using? I believe this code is depreciated in CRM 2016.
    Friday, February 10, 2017 9:32 AM
  • I would start by commenting all the lines out in the function, add an alert to ensure the function is being called then add individual lines until it breaks.

    I always find script debugging hard!

    Matt

    Friday, February 24, 2017 2:50 PM