JavaScript Querying the CRM2011 Web services

As we all know JavaScript is a Script language that executes on the client machine-browser. Based on the information loaded in the current opened page-form we can do many actions all of them executed on the client machine without needing the network connection (hide/show fields, modify attribute values, check the current user role… and more ). These JavaScript features make faster the system response to the user actions.

But sometimes we need information about CRM entities not included in the current page-form so we need to query the CRM2011 web services to get more data,create, update or delete records or make other service calls.

To archive this goal with JavaScript we can use 2 methods:

Both ways are fully documented in the SDK but if you don’t feel like reading it all i will explain here the easiest way to use both of them and the libraries needed.

The main different for me is that I used Asynchronous calls with ODATA(although u could change the Ajax query type to make them synchronous) and Synchronous calls with Fetch.

By Asynchronous I mean that the JavaScript execution will continue after making the QueryCall without waiting for the response indicating in the query to which function will have to call the server after executing the QueryCall.

When the query has been executed it will call this “return” JavaScript function where we will be able to process the result data.

A synchronous call will wait until the execution has finished to continue with the next instruction.

Reading some posts about these two ways of querying CRM2011 people comment that the Rest End Point is more efficient but you can only use simple commands (Retrieve,Create,Update or Delete records) while the SOAP end point is a bit slower but lets you make more complex actions(like making service requests).

Both ways of interacting with the CRM2011 Web Services are useful and fully working so i suggest you read both posts and decide which one fits you better.

Have a nice day,

Hache

Advertisements

2 thoughts on “JavaScript Querying the CRM2011 Web services

  1. mhernandezepa

    The REST endpoint provides a ‘RESTful’ web service using OData protocol to provide a programming environment that is familiar to many developers. It is the recommended web service to use for tasks that involve creating, retrieving, updating and deleting records. However, in this release of Microsoft Dynamics CRM the capabilities of this Web service are limited to these actions. Future versions of Microsoft Dynamics CRM will enhance the capabilities of the REST endpoint.

    The SOAP endpoint provides access to all the messages defined in the Organization service. However, only the types defined within the WSDL will be returned. There is no strong type support. While the SOAP endpoint is also capable of performing create, retrieve, update and delete operations, the REST endpoint provides a better developer experience. In this release of Microsoft Dynamics CRM the SOAP endpoint provides an alternative way to perform operations that the REST endpoint is not yet capable of.

    I personally use REST with JQuery & AJAX in my JScript web resources. REST is also used in silverlight client. In my plugins and custom workflow activities I use SOAP.

    The following table describes the appropriate web service to use depending on the task you need to perform.
    Task Web Service
    Create, Retrieve, Update and Delete records.

    REST Endpoint

    Associate and Disassociate records

    REST Endpoint

    Assign Records

    SOAP Endpoint

    Retrieve Metadata

    SOAP Endpoint

    Execute Messages

    SOAP Endpoint

    REST represents Representational State Transfer. REST is an architectural style in which every resource is addressed by using a unique URI. The REST endpoint provides an alternative to the WCF SOAP endpoint, but there are currently some limitations. Only Create, Retrieve, Update, and Delete actions can be performed on entity records. Messages that require the Execute method cannot be performed.Associate and disassociate actions can be performed by using navigation properties.

    For example in REST to list a specific Account, request xrmservices/2011/organizationdata.svc/AccountSet(guid’b9436b0d-b832-e011-9e40-00155da9cd4f’).

    I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s