Hello.
Could I know how to mimic "setTimeout" in SuiteScript 1.0 in server script please?
v
verikott
04/09/2024, 10:02 AM
What are you trying to achieve?
b
Boris Yasen
04/09/2024, 10:03 AM
I was going to run a function after sleeping 0.2 sec.
I think I have to run while loop manually
r
raghav
04/09/2024, 10:24 AM
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
battk
04/09/2024, 1:51 PM
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
Shawn Talbert
04/09/2024, 2:18 PM
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
Anthony OConnor
04/09/2024, 3:22 PM
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