Hi all,
When querying data using web api,not able to retrieve the data.When i debugged "readystate" is 1 but it should be 4 What is the issue and do i need to add any code?
*This post is locked for comments
Hi all,
When querying data using web api,not able to retrieve the data.When i debugged "readystate" is 1 but it should be 4 What is the issue and do i need to add any code?
*This post is locked for comments
Hi ,
Please try to copy the code which I have shared ? its should be without ().
see there is a difference code -
Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts()
Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts?
its not working with changing the version also
Hello ,
Try with changing the version , if you have v9.0 it will also work with v8.2 .
function Practice()
{
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts?$select=address1_city,name&$filter=address1_city eq 'Sydney'", 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);
for (var i = 0; i < results.value.length; i++) {
var address1_city = results.value[i]["address1_city"];
var name = results.value[i]["name"];
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
yea justin, am able to get in the browser...I tested
Hi aric,thanks for your reply.Below is the code.am calling function onchange of a field.
function Practice()
{
var req = new XMLHttpRequest(); //req object
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/accounts()?$select=address1_city,name&$filter=address1_city eq 'redmond'", false); //query
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 result = JSON.parse(this.response);
alert(result.length);
for(var i=0;i<result.length;i++)
{
var name = result.value[i]["name"];
alert(name);
}
}
else
{
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
Can you please share what you are trying to do? Code if possible?
What version of Dynamics CRM are you on (8.x, 9.0), and how did you create the WebApi calls?
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
52
Victor Onyebuchi
6