Make server side code wait

オフライン

Hi Community,

Hopefully an easy question -

I am calling a server side method from a client method and I need the server side method to wait a few seconds to allow the items to save before processing. I tried the standard sleep commands but they don't seem to work. I also tried to use a timeout on the client side but since I am closing the window after the save, it sometimes will not allow the code to continue.

Any suggestions?

Parents
  • Hi Morgan

    do you really need your server Method to wait? Or shall your client Method wait until the Server Method is finished?

    Typical scenario: You have a dialog with button. The onClick button event calls a server Method. When client Method is finished, you want to close the dialog and throw an success or failed notification based on the server Method result.

    If you have a long running server task, it can happen that the client Method tries to analyze the result of the server Method, while the server Method isn´t finished yet. In this case it can happen that dialog closes and you get wrong notification. This is normal JS behavior. It never waits.

    If this is your scenario, you have to call the server Method inside a promise or use async/await. This way you force the client code to wait. 

    Angela

  • 0 オフライン in reply to AngelaIp

    Hi Angela,

    The idea is that I am trying to reduce the time the user is spent waiting for the item to save and the server side method to complete its long task, which is why I am immediately calling the server method then closing the window. As unlikely as an error would be, in the case the server method fails, it sends an error message email to myself so I don't need to worry about bothering the user with a resolution.

    The main issue is that in the client method, I run the OOB onDoneCommand() which can take some time to save the item (about 3-10 seconds) depending on file uploads. In this case, the ID changes and the server method gets an old version ID to action. I am grabbing the item with a query based on keyed_name which is passed to the server method prior to the client window closing.

  • Interesting use case. Normally sounds like a background task for Conversion Server. 

    Which ID to you refer to? Is the ID changed due to versioning? In this case you could use the config_id to look up the items. You can filter for the lastest version of the item to get the latest id.

Reply Children