Skip to main content
Nintex Community Menu Bar
Question

Function that returns the value from updateData

  • July 9, 2024
  • 3 replies
  • 22 views

Forum|alt.badge.img+6

what would be the proper way of coding this function:

793199aa064ec7592154b0a9acb851132d2c41e2.png

retValue gets set in the callback from the model.updateData().  The problem seems to be that the function is returning before the callback is called, hence, returning zero.

Can we make the function wait until the callback is done before returning?  If so how would you do that?

Any thoughts?

Thank you.

This topic has been closed for replies.

3 replies

Forum|alt.badge.img+11

updataData() is asynchronous.  

Here’s a pattern that I use and you should be able to adopt it for your needs.

var deferred = $.Deferred();<br>...<br>$.when(myModel.updateData())&nbsp; &nbsp; &nbsp; &nbsp; <br>&nbsp; &nbsp;.done(function () {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Success &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deferred.resolve(); &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp;})<br>&nbsp; &nbsp;.fail(function () {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// Error<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deferred.reject();<br>&nbsp;}); ...<br>return deferred.promise();






Forum|alt.badge.img+6

Thanks for your input:

I tried this and I still get the same issue. You suggested to use $.Deferred() which is probably the piece I am missing. I am not familiar with $.Deferred() so I am going to investigate. Am I on the right track?


Forum|alt.badge.img+17
  • Nintex Employee
  • July 9, 2024

Do investigate the Deferred paradigm.  There are a number of community posts here where it is explained.