Need to pause business rule execution for sometime in particular condition

Chaithanya6
Tera Contributor

How can i pause the business rule execution in particular condition for the sometime 

3 REPLIES 3

AndersBGS
Tera Patron
Tera Patron

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:

 

  1. Open the Business Rule:

    • Navigate to "System Definition" > "Business Rules."
    • Search for and open the specific business rule that you want to modify.
    •  
  2. 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/

surbhi9
Tera Contributor

Ankur Bawiskar
Tera Patron
Tera Patron

@Chaithanya6 

What's the use-case to pause?

I won't recommend using gs.sleep() in BR script.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader