Delay in Java Script

Hi team.

I need to include a delay in java script for some requirements web services. I did this code but I feel that the function setTimeout is not in the set of the instructions.

Does anybody know how can include a delay in javascript
thanks a lot

var y=system.functions.tod();
print(y);


setTimeout(doSomething,3000);

function doSomething() {
//do whatever you want here
var z=system.functions.tod();
print(z);
}                       

  • Verified Answer

    Hi 

    SM js executung on server side,  setTimeout will  not work 

    Try this 

    var timeOut  = new Date(new Date 30000).valueOf()
    var current  = new Date().valueOf()
    while (true) {
      if (timeOut<current) {
        //your web service call here 
        return;
        }
      }

    HTH

     

  • Yeah, webservices do need a delay sometimes.

    I've therefore coded a "delay" by opening a long text file for reading and looping it through just to keep server busy and not throwing a timeout exception.

  • And forgot, newer versions of SM contain the popular Underscore JS library, which contains timeout functionality, but. in SM implementation..

    if(!this.setTimeout) {
      function setTimeout() {
        throw new Error("Service Manager doesn't support setTimeout function!");
      }
    }

    ...so if you'd like to use timeout in GUI programming, it's not possible.

  • While executing this in SV Designer 5.3 observing the below error...

    Syntax Error: Illegal return statement at Scripted Rule 1 -> return;
  • Hi Sivaraamakrishna,

    I don't know the SV Designer but just change the script and give it a return value like true or something else...

     

    var timeOut = new Date(new Date 30000).valueOf() var current = new Date().valueOf() while (true) { if (timeOut<current) { //your web service call here return true; } }

     

    Anyway, such while(true)... loops like this tend to overload the application server!

    There is a good RAD function for delay and easy to implement:

    var delayInSeconds = 30; system.functions.sleep(delayInSeconds); //your web service call here

    Disclaimer: The script is just from scratch und not testet!

    Give it a try!

    Bo