Monday, October 19, 2015

CRM SOAP Library – sdk.soap.js Part 1

This blog post is related to the CRM soap library created by the CRM SDK team last year. This library helps with writing JavaScript for web resources using SOAP endpoints just like C# code.  I am surprised that it only has 2600 downloads. I believe more people should use it. It provides a lot of functionality and will help to reduce code duplication in a project.
The library includes 2 files:
  • Sdk.Soap.min.js This is the minified version of the library. The size of the file is around 164kb.
  • Sdk.Soap.vsdoc.jsThis file should be used at design time to add IntelliSense to JavaScript

Advantages/Benefits

The following lists some of the benefits/advantages of using this library.
  1. Writing JavaScript like C#
    The library helps you to write JavaScript like C# code. It provides object models, methods and messages like C#. It is more productive if you are a C# developer.

  2. IntelliSense
    The Sdk.Soap.vsdoc.js file contains comments for the developers. It will be used at design time to provide IntelliSense. You just need to add a reference directive on the top of your .js file as shown below:
    /// <reference path="..path/Sdk.Soap.vsdoc.js" />

  3. Choice of Early Bound and Late Bound Classes
    The library provides the option to chose early binding and late binding in your code. I prefer the late binding but other people may prefer early binding classes as it provides the IntelliSense at design time for CRM entities. The solution also provides an early binding class entities generator to generate early bind classes for CRM entities. It is an equivalent of  crmserviceutil.exe

  4. Choice of Namespaces
    The library supports the following 8 core IOrganisationService methods.
    Associate,Create, Delete, Disassociate, Execute, Retrieve, RetrieveMultiple and Update.

    The library provides the 4 different namespaces that implement these core methods:


    • Sdk.Async:  It executes the methods asynchronously. The method signatures provide the  successCallBack and errorCallBack parameters.
    • Sdk.Sync:  It executes the methods synchronously.
    • Sdk.jQ:  It is an alternative approach to implementing asynchronous operations. It returns a jQuery.Deferred object/Promise. The initial state of the object is pending. The code will wait until the promise is resolved or rejected to execute the next line of the code.  In short, it is like writing synchronous code for asynchronous calls. I will post some sample code to explain the difference between callbacks and promises at a later date.

      This namespace depends on the existence of the jQuery.
                 
    • Sdk.Q:This is also the implementation of the “Promise” concept discussed above in Sdk.JQ.

  5. Messages/Actions
    Apart from the 8 core methods, the library supports 202 different methods. The library also provides a utility to create methods for custom action methods.

  6. Supported Queries
    The Sdk.Soap.js library supports the three main query styles used with retrieve operations:

Things to consider

  1. The library was originally written for CRM2013. The Sdk.Xml.getEnvelopeHeader function specifies an SdkClientVersion value of 6.0. It does work for CRM2013 and CRM2015. It may change in future.
  2. It does not contain all the messages.Please check the documentation on the libarary page.
  3. Delete the messages that are not required for your project to reduce the size of the JavaScript file.
  4. Delete the namespaces that are not required
Downloads
    Here is the list of the downloads for the library:
  1. Sdk.Soap.js (contains the core libraries)

  2. Sdk.Soap.js Entity Class Generator (tool to create libraries for CRM entities for ‘early binding’ and IntelliSense)

  3. Sdk.Soap.js Action Message Generator (tool to generate the support libraries for custom actions in your organization.
  4. Sdk.Soap.js Samples (code sample using the library)

 

5 comments: