delaying business rule from running

Thedavisrun
Mega Expert

I want to delay the notification sent out when a HR Case is set to state "Awaiting acceptance".

The reason is when the ticket is set to awaiting acceptance the email goes out stating that the ticket has been resolved.  But we want that mail to not go out until the ticket is in awaiting acceptance for 4 hours. 

So if the ticket is changed back to work in progress the business rule does not run at all.

We want to avoid also that the notification is just delayed.  We want to make sure if the state is changed from AA that 4 hours after the case was originally set to awaiting acceptance a notification doesn't get sent out even though the ticket is currently in a different state. 

 

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi , 

You can use gs.sleep(240000) function in business rule script .It will delay the business rule script execution.

 

Please mark as helpful (or) correct if it resolved your issue.

 

Thanks,

Sumanth

View solution in original post

4 REPLIES 4

Dubz
Mega Sage

You can use the gs.eventQueueScheduled() method as documented here

This way you can generate an event that will execute at the time you pass in as the object expiration, once it triggers you can use it to trigger a notification.

Sumanth16
Kilo Patron

Hi , 

You can use gs.sleep(240000) function in business rule script .It will delay the business rule script execution.

 

Please mark as helpful (or) correct if it resolved your issue.

 

Thanks,

Sumanth

I used the gs.sleep in the end.  simplest thing.  I had to recreate teh BR on the global scope however.

 

I didn see the below as a solution if not able to move the scope:

function pause(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; 
  }
}
pause(5000);

Chavan AP
Tera Guru

hi please refer below script:

refer link: https://community.servicenow.com/community?id=community_question&sys_id=5d984b21db5cdbc01dcaf3231f96...

below is an example similar to what you want to acheive, instead of 2 min you can amend it for 4 hours

var when = new GlideDateTime();


var delay = new GlideTime();


delay.setValue("00:02:00");


when.add(delay);



gs.eventQueueScheduled("mssql_host_change", current, "", "", when);

 

if this resolves your query please mark correct and helpful

regards,

ajay

Glad I could help! If this solved your issue, please mark it as Helpful and Accept as Solution so others can benefit too.*****Chavan A.P. | Technical Architect | Certified Professional*****