gs.sleep() in scoped application?

Artemis15
Kilo Guru

Hi,

gs.sleep(0 function is not working in scoped application?   Is there any workaround?

4 REPLIES 4

coryseering
ServiceNow Employee
ServiceNow Employee

Hi Akash,



You cannot use sleep in Scoped Apps. You shouldn't even use it in non-scoped apps.


There is no work-around. If you need to wait for a condition, you need to factor your code to be asynchronous and use callbacks.


lss123
Tera Contributor

Here's my workaround:



/* time is in milliseconds - this is essentially a "sleep" function */


wait: function(time){


  var t1 = new GlideDateTime().getNumericValue();


  var t2 = new GlideDateTime().getNumericValue();


  var duration = t2 - t1;


  while(duration < time){


  t2 = new GlideDateTime().getNumericValue();


  duration = t2 - t1;


  }


},



spinol
Kilo Explorer

I'm currently trying to use this workaround. Can someone point me in the right direction on where to place this wait function? Do I place it within the Script Include and then call it on the Client side so it awaits that response?

 

Thanks!

AnukampaK
Tera Contributor

Please check if you can use retry policy. you can set time interval as well as no of times request will be called in case of any condition like time out etc