Notifications
Announcements
No record found.
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
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?
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();
Hi tejagupta,
are you able to get the result in browser? can you try this on browser.
https://xxxxxx.crm4.dynamics.com/api/data/v9.0/accounts()?$select=address1_city,name&$filter=address1_city eq 'redmond'
Thanks
Justin Jose
yea justin, am able to get in the browser...I tested
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(); }
its not working with changing the version also
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?
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
SA-08121319-0 4
Calum MacFarlane 4
Alex Fun Wei Jie 2