Hold The Business Rule for 15 mins

AbdulNow
Tera Guru

I have a requirement if we mid Sever is down , We have to  create a incident but one condition as After 15 mins and if mid sever is up within 15 mins then no action required .

 

I'm trying to achieve by BR and adding gs.Sleep() but it is not working and also making instance very slow.

 

Please Help Guys .. Much Appreciate!   

1 ACCEPTED SOLUTION

Lukasz Bojara
Kilo Sage

Hi,

What you could do is register your own event and delay its processing. Then you will set up a Script Action on that to create incident.

 

For example (I have used Change Request) register new event:

find_real_file.png

 

Next step is to create Script Action to handle the event:

find_real_file.png

When you will have those 2, the last part is to create a Business Rule that will react when a value changes (for me when change request is cancelled) and in Advance write somethin like this:

(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var whenTrigger = new GlideDateTime(); // get current datetime
	whenTrigger.addSeconds(180); // add 3 minutes
	
	gs.eventQueueScheduled('test.scheduled.event',current,current.number,'Scheduled on ' + whenTrigger.getDisplayValue(),whenTrigger);

})(current, previous);

When BR will fire the event you will see in logs that it is deleyed:

find_real_file.png

 

After the time the event will be processed and Script Action will create an Incident.

find_real_file.png

find_real_file.png

Hope this helped.

 

Best regards,
Łukasz

 

View solution in original post

6 REPLIES 6

Hello Łukasz,

What's the value for 'When' in When to Run tab for Business Rule? Should it be before, after, async or display?

It's all up and running, but it's creating 2 incidents. 1 incident is created right after the CR is cancelled. Another incident is created after the 'whenTrigger', which is in 3minutes.


Regards,
Neal Castro

Hello neallor,

 

Business Rules run when specific database operations are performed e.g. INSERT or UPDATE. The When setting provides information on a time when  Business Rule should be triggered so if you will set it e.g. to Before and database operation will be INSERT then it means that Business Rule will be triggered before this operation, so first everything that BR is doing will be done and then the new record will be inserted. There are some best practises around using it, e.g. if you want to modify current record before it will be saved to the database you should set it to Before, if you want to update other record based on changes made to the current one then you should set it to After.

 

There is one very important rule that you should always follow: never use current.update() in Business Rules. This will trigger the BR once again and you will end up with an infinite loop of BRs.

 

As for your second note. Check if there is no other mechanism that creates this first incident. Also if you would show how you have set up your solution it would be easier to see what went wrong.

 

If my answer helped you in any way, please then mark it as helpful. If this solved your case please mark it as a correct answer. Thank You.

 

Best regards,

Łukasz