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?

  • 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. 


  • 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.

  • Unfortunately, my organization has elected not to use conversion server at this time so we are trying to get a little creative with some things. Our main concern right now is a lot of actions are pretty slow in Aras so we are trying to alleviate some of the time a user sits looking at the spinner.

    To answer your questions, yes the ID is changed due to versioning. I'll give that a try. The other issue is if the item isn't done being saved, then the current version doesn't exist yet and it will call the wrong version, hence the need for a wait. Thanks!

  • I completely understand your situation! I right now work on a similar task where I try to optimize a long running task (ZIP package builder). When packages are too large, users wait an eternity. Nobody likes watching a spinner.

    My current ideas are either using Conversion Server or do everything asynchronous. 
    There are forums posts regarding these ideas:

    While researching I discovered this old post:

    I used the mentioned solution to win some time between a file upload and file duplication/conversion.
    Maybe this one is an option for you? The post mentioned an onUnload event, but that never worked well (due to Innovator glitches in the Form unload events). But I changed it to an "onAfterUnlock" server event to trigger a second Method that does the file operation. The "timeout" is the time users spend to edit the form and upload the initial file. In my case the solutions isn´t use for a time consuming task, but works well to get some times between two server calls.

Reply Children
No Data