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();

How to Clear Cache in Canvas PowerApps while working on Offline mode?

  Introduction In this blog, we’ll look at how to clear cache in Canvas Apps when using the Power Apps mobile application, especially when t...