Snippet to create a delay in a server side script
I created this function because setTimeout doesn’t exist in server side Netsuite. I have never had the need to use it, but I thought someone else would find it useful.
Insert this function in your code:
1 2 3 4 5 6 7 8 |
function setTimeout(aFunction, milliseconds){ var date = new Date(); date.setMilliseconds(date.getMilliseconds() + milliseconds); while(new Date() < date){ } return aFunction(); } |
And then call it like this:
1 |
setTimeout(function(){ log.debug('Ran after 1 second'); }, 1000); |
Beware of execution time limits when running this code. Always test first.