Need to pause business rule execution for sometime in particular condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 01:48 AM
How can i pause the business rule execution in particular condition for the sometime
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 01:54 AM - edited 08-01-2023 02:05 AM
To pause the execution of a business rule in a particular condition for a specific period of time, you can use the gs.sleep() method within the business rule script. This method will pause the script execution for the specified duration and then resume it afterward. Here's how you can achieve this in ServiceNow:
Open the Business Rule:
- Navigate to "System Definition" > "Business Rules."
- Search for and open the specific business rule that you want to modify.
Add the Pause Logic:
- Inside the business rule script, identify the condition where you want to pause the execution.
- Use the gs.sleep(milliseconds) method to pause the script execution. The argument milliseconds specifies the duration of the pause in milliseconds.
Here's an example of how you can implement this in a business rule script:
(function executeRule(current, previous /*, g*/) {
// Check the condition where you want to pause the execution
if (current.state === 2 /* state 2 represents "In Progress" */) {
// Pause the execution for 5 seconds (5000 milliseconds)
gs.sleep(5000);
}
// Your remaining business rule logic goes here
// This part will execute after the sleep is completed
})(current, previous);
In this example, the business rule checks if the incident's state is "In Progress" (state 2). If the condition is met, the script will pause for 5 seconds using the gs.sleep(5000) method. After the 5 seconds, the script will resume executing the remaining logic.
If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Best regards
Anders
If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.
Best regards
Anders
Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 01:58 AM
Please check this post-https://www.servicenow.com/community/developer-forum/gs-sleep-in-business-rule/m-p/1627305
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-01-2023 02:16 AM
What's the use-case to pause?
I won't recommend using gs.sleep() in BR script.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader