function retrieveMultipleRecords(entityName, query) { var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/" + entityName + query, 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=*"); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var results = JSON.parse(this.response); console.log(results); // Example of handling the retrieved data var resultArray = results.value; resultArray.forEach(function (record) { console.log("Name: " + record.name + ", Account Number: " + record.accountnumber); }); } else { console.error(this.statusText); } } }; req.send(); }