Automated Testing Framework - Issue following KB article to add sleep function in the Scoped app

Latoya
Kilo Guru

I attempted to follow this article below, but I am not executing it correctly

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0962370

This is what I have below based on the article

MicrosoftTeams-image.png

MicrosoftTeams-image (1).png

1) Should I put the actual time I need in the (time) option for the script include or leave this as is?
2) How do I call the function using global.<script>? I assumed this meant using the run server-side script in the ATF

The step passes but it is not actually delaying the steps so something needs to be changed.

 

Goal: I want to add a 2 minute delay between updating a record step and verifying the state for a RITM step using the gs sleep function in a scoped application

 

I need an example of using this KB's guidance in an ATF so I can see how to actually achieve the desired results.

Thanks a bunch

 

  

1 ACCEPTED SOLUTION

Latoya
Kilo Guru

I was able use this in the Run server side script and it worked

 

Latoya_0-1710343002639.png

2000 is the delay time so for 2 minutes replace 2000 with 120000 

View solution in original post

3 REPLIES 3

Sumanth16
Kilo Patron

Hi @Latoya ,

 

Details

 

A scoped application doesn't honor direct use of "gs.sleep()" function in "Application scope" scripts.

 

Instructions or Steps

The "gs.sleep()" function can't be used in scoped application scripts, as this falls under the global scope. But to make use of this function follow the below process.

 

  • You can create a "script include" in the global scope and make sure the "Accessible from" is set to "All Application Scope"
  • Create a custom function in the script include and within that use "gs.sleep()"

         Example:

var SleepForScoppedApp = Class.create();
SleepForScoppedApp.prototype = {
    initialize: function() {},
    sleep: function(time) {
        gs.sleep(time);
    },
    type: 'SleepForScoppedApp'
};
  • Now call this function from any application scope scripts to make use of the "gs.sleep()" functionality. Make sure to use "global. <script>" format to call the function as this scripted include is created in global application

I read this support article today and got this useful information 

Supported ServiceNow Article: How to make use of gs.sleep() in a scoped application scripts - Support and Troubleshooting (service...

 

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda

Thanks for the response but as I mentioned, I am aware of the KB article and included it in my original post. The issues is executing it properly

Latoya
Kilo Guru

I was able use this in the Run server side script and it worked

 

Latoya_0-1710343002639.png

2000 is the delay time so for 2 minutes replace 2000 with 120000