How to control/restrict action framework not to go to next action while current action's snippet is

edited June 25, 2020 in Questions
Hi,

I have a button which has multiple actions to run on click.

Action 1: Run a Snippet
Action 2: Another snippet
Action 3: Run 3rd Snippet

Here , what I am trying to achieve is - only after finishing the first snippet which saves my record and then start running other ones

But currently, what is happening is - I observed that 3rd snippet is running before the first action in list.

This is how my action framework looks like:

image


Here is my first snippet looks like:

// Get references to our Models//Define Variables required

var $ = skuid.$;
var mainDFD = $.Deferred();
var models = skuid.model.map();
var bpModel = models.BillingProfile;

//Save Billing Profile

var saving = skuid.model.save([bpModel],{callback: function(result){
    if (result.totalsuccess){
        
        //alert('Billing Profile Id: ' + bpModel.getFirstRow().Id); // should be a real SF Id now
        //console.log('Billing Profile - ID ',bpModel.getFirstRow().Id);
        //$.unblockUI();
        //mainDFD.resolve();
    
    } 
    else {
        // There was a problem. Let's see what went wrong.
        
        alert('Billing Profile Save Error:
' + result.insertResults[0]);
        console.log('Billing Profile - Save Error',result.insertResults[0]);
        
        //mainDFD.reject();
        //$.unblockUI();

        }
} //close-Clallback
    
});

///************* 
 saving.done(function(result){
    if(result.totalsuccess){
        
        console.log('Billing Profile - ID - From Saving.done',bpModel.getFirstRow().Id);
        //bpModel.doQuery = true;
        
        $.unblockUI();
        mainDFD.resolve();
    }
    else{
        mainDFD.reject();
        $.unblockUI();
    }
});
//*****************/



The main issue is without having this record id which is being saved by first snippet, the 3rd snippet is failing and always throwing an error.

How can we keep action framework wait until we finish this first action (first snippet) and go on when done.


 

Comments

  • Pat VachonPat Vachon 💎💎💎
    edited June 25, 2020
    Do you know that the first snippet is working.

    Also, looks like first snippet is missing "return dfd.promise();" as last line.

    Lastly, why not use "Show Message and Block UI" error option on first snippet?
  • edited July 12, 2016
    Yah - My bad. I missed the - return dfd.promise();  at the end of snippet.

    That resolves the issue.

    Thanks Pat!

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!