How to stop running business rule on specific period of time
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 03:39 PM
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 ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 03:43 PM
it is possible. add your logic in a script inclue and call the script inclue from the BR condition field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-08-2024 04:53 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 02:38 PM
Thank you, please let me try your solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-09-2024 02:46 PM
Let me know how it goes