Trying to set a delay in the script

Ella1
Kilo Expert

I am trying to set a delay in the script and after 1 sec I want the queries to run, but I am unable to see the logs and the code is not executing at all line 64 log is not visible in the logs
find_real_file.png

8 REPLIES 8

sachin_namjoshi
Kilo Patron
Kilo Patron

You can use below code for sleep function

 

 

 

  1. /* time is in milliseconds - this is essentially a "sleep" function */  
  2. wait: function(time){  
  3.   var t1 = new GlideDateTime().getNumericValue();  
  4.   var t2 = new GlideDateTime().getNumericValue();  
  5.   var duration = t2 - t1;  
  6.   while(duration < time){  
  7.   t2 = new GlideDateTime().getNumericValue();  
  8.   duration = t2 - t1;  
  9.   }  
  10. },  

 

 

from here: gs.sleep() in scoped application?

 

Regards,

Sachin

it is in a scoped application yes

sleep cannot be used in scoped applications.

-Anurag

Create a Script Include in Global Scope, Accessible from All AplicationScopes and use below code

 

var MyGlobalScopeUtils = Class.create();



MyGlobalScopeUtils.prototype = {



      initialize: function() {



      },



 



        /** Wrapper for gs.sleep



        *



        * @param {Integer} duration in ms



        */



      sleep: function (duration) {



              gs.sleep(duration);



      },



 



      type: 'MyGlobalScopeUtils'



 



};

 

In your scoped scripts you can use

 

var globalUtils = new global.MyGlobalScopeUtils(); //

globalUtils.sleep(1000);

 

Regards,

Sachin