Thursday, June 16, 2011

Tips for using REST endpoints in CRM 2011(Rest endpoints browser)

Using REST endpoints with json2 are the simplest way to retrieve data in CRM 2011. The code is clean and simple. Here is a sample retrieve request

retrieveAccountsReq.open("GET", getRESTUrl() +

"/new_postcodeSet?$top=20&$select=new_name,new_Country,new_Suburb,new_State,new_postcodeId&$filter=new_name
eq ('"
+ postcode + "')", true);


The above request is used to retrieve the custom entity (new_postcode) dataset where new_name is equal to postcode.

The result will look like this
image
To get the fieldnames for an entity you can use http://servername:portnumber/organization name/XRMServices/2011/OrganizationData.svc/entitySet

The result will look like this

image

You can even paste the query in the browser and check the result of the query. The following query will display all the records with postcode 2010.

http://tcrm2010:5555/CRM/XRMServices/2011/OrganizationData.svc/new_postcodeSet?$select=new_name,new_Country,new_Suburb,new_State,new_postcodeId&$filter=new_name

The result will look like this

image

Conclusion

REST endpoints are the best way to retrieve data on client site. You can even see the result of the query in the browser.

Happy Programming……..

6 comments:

  1. Nice info, however I can't seem to get any custom entities to work (even using the prefix)

    ReplyDelete
    Replies
    1. What's the error message? I am using custom entity new_postcode in the above examle.

      Delete
    2. Singh, i created a custom field called "field_A" for contacts, noticed it appeared in the ContactExtensionBase table. How do i get "field_A" from this table.

      For AccountBase look at the code (it works perfectly)
      var filterx = '/AccountSet?';
      var filterz = "$select=AccountNumber,AccountId&$filter=AccountId eq (guid'" + accid + "')";

      now to get "field_A" from ContactExtensionBase i go like this
      var filterx = '/ContactExtensionSet?';
      var filterz = "$select=new_CustomerID&$filter=ContactId/Id eq (guid'" + accid + "')";

      i get error 404 for XMLHttpRequest status.
      Thank you.

      Delete
    3. Got the Solution
      Used ContactSet instead of ContactExtensionSet

      var filterx = '/ContactSet?';
      var filterz = "$select=new_CustomerID&$filter=ContactId eq (guid'" + accid + "')";

      Delete
  2. Is it possible to query using lookup text value in crm jscript?

    ReplyDelete
  3. Microsoft Dynamics CRM training will help you manage and prioritize your business goals, customize.we teach MS Dynamics CRM training and class available at Hyderabad.

    ReplyDelete