Question regarding adding delay in a script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
Hi Community,
https://www.servicenow.com/community/developer-forum/need-delay-function-for-script/m-p/1409922
I recently stumbled across this article where @Ankur Bawiskar has suggested a way to incorporate a delay in a script. Tried it, and it is working as expected. But, few doubts not leaving from my mind.
1. Is this the correct approach?
2. Should we use this in an actual implementation (if there's no other way to satisfy the requirement)?
3. Impact on performance?
4. Any alternatives?
Awaiting response from community as well as Ankur 🙂
Regards,
Ritik
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@nirwan_ritik, what was the use case for which you added delay in script? If you provide the complete context of what it was all about may be community can think.
Please don't post questions with suspense.
We are not Albus Dumbledore. Jk...
Regards,
Vikas K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
OOPS, forgot to add the link.
https://www.servicenow.com/community/developer-forum/need-delay-function-for-script/m-p/1409922
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago - last edited 3 weeks ago
@nirwan_ritik, I see ServiceNow developers have used "sleep" in several Script Includes. Pasting a few here for your reference.
This looks okay because if there is a reason to delay the execution of the particular code or function to establish something then you can't help it. See some snips from OOB script includes I have pasted below. It all depends on use case.
Alternate method - You can also call the script include in any other place if you ever see any issues in performance. For example, scripted Scheduled Jobs, Flow Designer Action etc... but use it wisely and sparingly.
By the way if it was really impacting performance, ServiceNow Dev's won't use it and sell the product to their customers worldwide. (Would cause serious issues brah!)
Some examples of how and where ServiceNow Dev's used gs.sleep in their code. You can open them in your instance and check the use case for which they used it.
Hope this helps!
Regards,
Vikas K
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
ServiceNow do use sleep in many of the OOTB scripts so it should be fine to use.
It varies from customer to customer and based on requirement as well.
yes it will have some performance impact as you are making system wait on particular thread for particular timeframe.
what's your business requirement to use delay?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader