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

Not sure Supriya25 understands GlideDateTime uses UTC so logic works in any timezone, duplicate thread here:

 

https://www.servicenow.com/community/developer-forum/why-quot-isinschedule-quot-always-entering-else...

 

Business rule script:

 

 

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

	// Add your code here
	var now = new GlideDateTime();
	gs.info("my business rule: checking date/time: " + now + " utc");
	var schedule = new GlideSchedule("090eecae0a0a0b260077e1dfa71da828"); // 8-5 weekdays excluding holidays
	if (schedule.isInSchedule(now)) {
		gs.info('my business rule: now (utc) is in Schedule');
		// add logic here for what to do when current date/time falls in the schedule
		gs.addErrorMessage(gs.getMessage("changes are not allowed curing 9 - 6 weekdays."));
		current.setAbortAction(true);
	} else {
		gs.info('my business rule: now (utc) is Not in Schedule');
		// add logic here for what to do when current date/time does not fall in the schedule
		//do nothing, allow the update outside of the schedule.
}

})(current, previous);

Create a schedule for 9 - 3 weekdays excluding holidays and use that schedule in the above

 

my Instance always runs in EST time-zone

That is false.

All instances run in UTC and all dates and date/times are stored in UTC in the DB.

It is only when a date/time value is displayed that it is 1st converted into the current user's TZ.

Also when a data/time is saved, it is 1st converted from the current user's TZ to UTC and the UTC value is stored.

 

There are date/times that convert to and from different time zones than the current user's TZ, e.g. Calendar Date/Time or UTC Time, but even then those still work internally in UTC and are stored in UTC.