The CreatorCon Call for Content is officially open! Get started here.

How to stop running business rule on specific period of time

Supriya25
Tera Guru

Hi Team,

 

we have two business(insert, update operation) , which plays major role in daily activity.

This two Business rules should work only between morning 6AM-afternoon 3PM.  after 3PM/before 6AM if any insertion/updating happens on record these BR's should not respond..

 

Every day we can't deactivate/Activate , so How can we achieve it ? any possibility ?

16 REPLIES 16

luffy3478
Tera Guru

it is possible. add your logic in a script inclue and call the script inclue from the BR condition field

Jim Coyne
Kilo Patron

Definitely an odd use case, but it is possible.

 

1. create a Schedule and configure your run times

2. in the Business Rules, add the following code:

(function executeRule(current, previous /*null when async*/) {
    //replace the sys_id with the id of the appropriate schedule
    //or use a System Property to avoid hard-coding
    var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828");
    if (schedule.isInSchedule(new GlideDateTime(gs.nowDateTime()))) {
        // Add your code that you want to run during that time period here
        ...
        ...
    }
})(current, previous);

The "isInSchedule" call will verify if the current date/time is within that time period and if so, will run your code.  The nice thing about using a Schedule is you can modify the Schedule to do testing or make changes to when it is allowed to run without touching any code, just a change in data.

 

You could also create a Script Include and call it from the Condition field, but not sure which is more efficient to be honest.  The nice thing about this is everything is self-contained.

Thank you, please let me try your solution

Let me know how it goes