How can I have a function wait until after a model update to run?

I was having issues with getting a function to run after a model updateData function was called. See below for a the answer.

Thanks to Matt and Pat for your posts on this!

http://community.skuid.com/skuid/top…


The main line of code from the below sample that provides the solution is

<br />$&#46;when(initialUpdateOrOtherDeferredFunction())&#46;done([printSuccess,doStuffAfterUpdateAttempt])&#46;fail([printFailure,doStuffAfterUpdateAttempt]);


See below for the rest of the solution

<br />$ = skuid&#46;$;<br />try{<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; &#47;&#47;both done and fail function take a function or array of functions as parameters&#46; I chose an array for both to print sucess state&#46;<br />&#47;&#47;<a href="https://api.jquery.com/jQuery.when/" rel="nofollow" target="_blank" title="Link: https://api.jquery.com/jQuery.when/">https:&#47;&#47;api&#46;jquery&#46;com/jQuery&#46;when/<br /></a>&#47;&#47;<a href="https://api.jquery.com/deferred.done/" rel="nofollow" target="_blank" title="Link: https://api.jquery.com/deferred.done/">https:&#47;&#47;api&#46;jquery&#46;com/deferred&#46;done/<br /></a>&#47;&#47;<a href="https://api.jquery.com/deferred.fail/" rel="nofollow" target="_blank" title="Link https//apijquerycom/deferredfail/">https:&#47;&#47;api&#46;jquery&#46;com/deferred&#46;fail/<br /></a>&#47;&#47;"Since deferred&#46;done() returns the deferred object, other methods of the deferred object can be chained to this one"<br />&#47;&#47;this is why &#46;fail can be appended to &#46;done<br />&nbsp; &nbsp; $&#46;when(initialUpdateOrOtherDeferredFunction())&#46;done([printSuccess,doStuffAfterUpdateAttempt])&#46;fail([printFailure,doStuffAfterUpdateAttempt]);<br />&nbsp; &nbsp;&nbsp;<br />}<br />catch(e){<br />&nbsp; &nbsp;&nbsp;<br />&nbsp; &nbsp; console&#46;log(e);<br />}<br /><br />function initialUpdateOrOtherDeferredFunction(){<br />var mod = skuid&#46;model&#46;getModel('modelName');<br />&#47;&#47;do pre-processing stuff to your model here<br />&#47;&#47;return the deferred promise<br />return mod&#46;updateData();<br /><br />}<br /><br /><br />function printFailure(){<br />&nbsp;<br />&nbsp; &nbsp; console&#46;log('Failure');<br />&nbsp; &nbsp;&nbsp;<br />}<br />function printSuccess(){<br />&nbsp;<br />&nbsp; &nbsp; console&#46;log('Success');<br />&nbsp; &nbsp;&nbsp;<br />}<br />function doStuffAfterUpdateAttempt(){<br />&#47;&#47;do stuff<br />&#47;&#47;do stuff<br />&#47;&#47;repeat stuff <a href="https://www.youtube.com/watch?v=nt9c0UeYhFc" rel="nofollow" target="_blank">https:&#47;&#47;www&#46;youtube&#46;com/watch?v=nt9c0UeYhFc</a><br />}