Monday, April 3, 2017

Call Fetch XML using Web API

Hi All,

Please find the code below to call Web Api with FetchXML.

var fetch = encodeURI("<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'></fetch>"); // Pass Fetch XML
     var entityname = "new_test";  // Pass Entity Name
     var serverURL = Xrm.Page.context.getClientUrl();
     var Query = entityname + "?fetchXml=" + fetch;
    var req = new XMLHttpRequest();
    req.open("GET", serverURL + "/api/data/v8.0/" + Query, false);
    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 ) // Completed
        {
            req.onreadystatechange = null;
            if (this.status == 200)
            {
                var data = JSON.parse(this.response);
                if (data != null)
                 {
                    // Call Success Call back Function
                }

            }
             else
             {
// Call Error Call Back Function
                var error = JSON.parse(this.response).error;
                alert(error.message);
            }
        }
    };
    req.send();

Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...