Retrieve All Records using fetch Xml in WebApi


///////////////////////AllEntityMetdata///////////////////////////////////////
var url = req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/EntityDefinitions", false);

/////////////////////////////////FetchRequest/////////////////////////////
var fetchxmlcode="<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
  "<entity name='account'>"+
    "<attribute name='name' />"+
    "<attribute name='primarycontactid' />"+
    "<attribute name='telephone1' />"+
    "<attribute name='accountid' />"+
    "<order attribute='name' descending='false' />"+
    "<filter type='and'>"+
      "<condition attribute='createdon' operator='last-x-hours' value='1' />"+
    "</filter>"+
  "</entity>"+
"</fetch>"
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/mtccup_calendars?fetchXml=" + fetchxmlcode, true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");//this request is used for record meta data
req.onreadystatechange = function () {
    if (this.readyState === 4) {
        req.onreadystatechange = null;
        if (this.status === 200) {
            var results = JSON.parse(this.response).value;
            CalendarDataSuccess(results);
        } else {
            Xrm.Utility.alertDialog(this.statusText);
        }
    }
};
req.send();

Comments

Popular posts from this blog

Basic Plugin Code in D365 using C#

CURD (Create, Update, Retrieve and Delete) Operation in D365 using Power Shell Script

Meta Data Using WebApiRequest