Can we make snippet to wait until called snippet execution completed

edited February 4 in Questions
if we are calling a snippet from another snippet like
var SaveQLIModels = skuid.snippet.getSnippet('SaveQLIModels');
SaveQLIModels ();
Can we make the current snippet to wait until SaveQLIModels snippet execution is completed.

I tried using
$.when(SaveQLIModels()).done(function(){
**Remaining logic**
})
but it not waiting until snippet SaveQLIModels() execution complete. Let me know what I am missing her.

Thanks in advance for the help.

Comments

  • Chandra VChandra V Member
    edited February 2019
    I think you need a call back function, which proceeds once your save is successful.

    skuid.model.save([MyModel], {callback: function(result){
    if (result.totalsuccess) {

    // rest of your logic
      
    } else {
    //logic if the save fails
    console.log(result.insertResults);
    console.log(result.updateResults);
    console.log(result.deleteResults);
    return false;
    }
    }});
  • edited March 2018
    Thanks Chandra for a quick reply.
    Here in my scenario, I am calling another snippet. so this
    skuid.snippet.getSnippet('SaveQLIModels'); 
    will return a function and that function should have a callback to execute the remaining logic?
  • Mark DeSimoneMark DeSimone Skuid Mod 🛠️ 
    edited February 4
    Dinesh, you might also be able to set up a Model Action on the model that's being saved. You can use "model saved" as the trigger, then set up an action sequence that runs the SaveQLIModels snippet. 
  • Mark DeSimoneMark DeSimone Skuid Mod 🛠️ 
    edited February 4
    By the way, if your SaveQULIModels snippet is just saving other models, you can set up the same kind of model action sequence to do that declaratively, whenever the first model is saved.
  • edited June 17
    @Mark, yes initially models save was defined declaratively and after that we are calling a snippet. but unfortunately all those declarative actions are firing asynchronously. So some time before save of models completed snippet is firing and it is holding the old data. That is the main reason, we wrote snippet for models save and calling another snippet on success of models save.
Sign In or Register to comment.