Hello. Could I know how to mimic "setTimeout" in S...
# suitescript
b
Hello. Could I know how to mimic "setTimeout" in SuiteScript 1.0 in server script please?
v
What are you trying to achieve?
b
I was going to run a function after sleeping 0.2 sec. I think I have to run while loop manually
r
Suitescript doesn't allow setTimeout. You can either use a while loop CurrDate = new date() While CurrDate + x amount of time < new date. Do note this method is not recommended, as if your x amount of time is huge you will hit the instruction count limit. Another way is to use to call an api which will respond back in x amount of time.
b
if you actually needed the setTimeout to make code run after a different task, then you can make the code run after a Promise resolves using the then method
s
I recommend the external API method rather than spinning in a loop. I think somebody, maybe @ExtendApps Inc. released an API for us all to use?
a
all good advice, if you just want to have a quick pause though I've had luck just doing a random search or a record load... anything that does a some kind of DB work will take some non-zero amount of time. but yeah that's pretty hacky so I don't really recommend it
131 Views