Block UI and show message until sforce.connection.remoteFunction() call completes

I’m having trouble getting this snippet to work with the deferred promise. I’ve got the same thing set up on other snippets working fine. What’s wrong here?

var params = arguments[0], $ = skuid.$; var dfd = $.Deferred(); // define and save model to search through for criteria var criteriaModel = skuid.model.getModel('Collateral'); criteriaModel.save({callback: function(result){ // if model saves, proceed if (result.totalsuccess) { console.log(criteriaModel+'save successful'); var rows = criteriaModel.getRows(); // set the model we are querying and define all conditions var templates = skuid.model.getModel('ConditionTemplateSearch'); var condition = templates.getConditionByName('CollateralCategories__c'); var leased = templates.getConditionByName('CollateralLeased__c'); var owned = templates.getConditionByName('CollateralOwned__c'); // set the destination model to push rows into var allTemplates = skuid.model.getModel('ConditionTemplates'); // for each selected row of the criteria model $.each(rows, function(){ var currentId = this.Id; // set conditions on the template search model var row = this; var isLeased = criteriaModel.getFieldValue(this, 'Leased__c'); console.log(isLeased); if (isLeased) { templates.activateCondition(leased); templates.deactivateCondition(owned); } else if (isLeased === false) { templates.activateCondition(owned); templates.deactivateCondition(leased); } var category = criteriaModel.getFieldValue(row, 'Category__c'); templates.setCondition(condition,category); // query the model and add any rows found to the allTemplates model templates.updateData( function(){ var newRows = templates.getRows(); allTemplates.adoptRows (newRows); } ); }); dfd.resolve(); // if save fails, do nothing } else { console.log(result.insertResults); dfd.reject(); } } }); return dfd.promise();<br>

I’m trying to run several snippets in a row, synchronously, and in this snippet the dfd is never recognized, the ui is never blocked, even if it Just have in my action framework, show message and block ui, this snippet, and unblock ui. 

I find the jquery $.when() more reliable than the .save(callback) method.

Have you tried
$.when(model.save())
    .done(function(){
       //do your work here
       dfd.resolve();
     })
     .fail(funcion(){
       dfd.reject();
     });

return dfd.promise();


Also, you might want to try
var dfd = new $.Deferred();

adding new worked, and then it didn’t. When it worked, it delayed the running of the second snippet until the first resolved, but never showed the block ui message. 

then it just stopped working. I’ve stopped trying to save, just trying to get the snippet to trigger a pause in the action framework until complete. can you help??

This is not pausing the sequence:

var $ = skuid.$; var dfd = new $.Deferred(); // define and save model to search through for criteria var criteriaModel = skuid.model.getModel('Property'); var rows = criteriaModel.getRows(); // set the model we are querying and define all conditions var templates = skuid.model.getModel('ConditionTemplateSearch'); //var condition = templates.getConditionByName('CollateralCategories__c'); var leased = templates.getConditionByName('RealPropertyLeased__c'); var owned = templates.getConditionByName('RealProperty__c'); // set the destination model to push rows into var allTemplates = skuid.model.getModel('ConditionTemplates'); // for each selected row of the criteria model $.each(rows, function(){ var currentId = this.Id; // set conditions on the template search model var row = this; var isLeased = criteriaModel.getFieldValue(this, 'Leased__c'); console.log(isLeased); if (isLeased) { templates.activateCondition(leased); templates.deactivateCondition(owned); } else if (isLeased === false) { templates.activateCondition(owned); templates.deactivateCondition(leased); } // var category = criteriaModel.getFieldValue(row, 'Category__c'); // templates.setCondition(condition,category); // query the model and add any rows found to the allTemplates model templates.updateData( function(){ var newRows = templates.getRows(); allTemplates.adoptRows (newRows); } ); }); dfd.resolve(); return dfd.promise();<br>