In previous post I explain use of Deferred Object in SharePoint REST API. In this post I’m going to explain use of Deferred object in JSOM/CSOM.

To use client context in the JavaScript you need to as below files in your page or masterpage as reference which is available in /_layouts/15/ folder.

  • inheritMicrosoftAjax.js
  • sp.runtime.js
  • sp.js

JQuery Deferred object can be used here too to make things simple, we have created a small example for that too.

functionToCall().done(function (returnedValue) {
     // do something with the returned value

function functionToCall() {
     var dfd = $.Deferred(function () {
     var valueToReturn = clientContext.get_web();
     clientContext.executeQueryAsync(function () {
          function (sender, args) {
               //throw an error
     return dfd.promise();

Hope this will help you and save your time..

Happy Coading… 🙂

Thanks, Jay Doshi

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s