web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

querying data using web api

(0) ShareShare
ReportReport
Posted on by

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

I have the same question (0)
  • Aric Levin - MVP Profile Picture
    30,190 Moderator on at

    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?

  • Community Member Profile Picture
    on at

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

    }

  • Justinjose Profile Picture
    2,707 on at

    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

  • Community Member Profile Picture
    on at

    yea justin, am able to get in the browser...I tested

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

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


  • Community Member Profile Picture
    on at

    its not working with changing the version also

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans