Need Help on Business Rule creation- check the details below
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
We need to create a Business Rule on the Email [sys_email] table in ServiceNow.
At the time of record insertion, the rule should check whether the email is created between 9:00 AM and 6:00 PM IST.
If the condition is met, the Type field should be updated to Send Ignored.
After i need Scheduled job should run after 6pm ist and updated the above emails to send Ready state
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Yes @Swathi KS ,
The error was because GlideDateTime doesn't have a .getHourOfDay() method. After debugging I came tot know that.
That's why the script fails.
So use this script this will work :
var now = new GlideTime();
now.addSeconds(19800);
// gs.print(now);
var hour = now.getHourUTC();
if (hour >= 9 && hour < 18) {
current.type = 'send-ignored';
//gs.print(hour);
}
If my response helped mark as helpful and accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
something like this as before insert/update BR on sys_email
(function executeRule(current, previous /*null when async*/ ) {
var strConvertedDateTime = new GlideScheduleDateTime(new GlideDateTime()).convertTimeZone("UTC", "IST");
var gdtConvertedDateTime = new GlideDateTime(strConvertedDateTime)
var hour = parseInt(gdtConvertedDateTime.toString().split(' ')[1].split(':')[0]);
if (hour >= 9 && hour < 18) {
current.type = 'send-ignored'; // Or sys_id of Send Ignored
}
})(current, previous);
Then scheduled job which runs at 6pm IST and marks that state
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hope you are doing good.
Did my reply answer your question?
💡 If my response helped, please mark it as correct ✅ and close the thread 🔒— this helps future readers find the solution faster! 🙏
Ankur
✨ Certified Technical Architect || ✨ 10x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @Swathi KS
Create a Before Insert BR & Use this Snippet
(function executeRule(current, previous /*null when insert*/) {
// Get current time in IST (UTC+5:30)
var now = new GlideDateTime();
var istOffset = 330; // IST = UTC + 5 hours 30 mins = 330 minutes
var utcMs = now.getNumericValue(); // current time in milliseconds (UTC)
var istMs = utcMs + (istOffset * 60 * 1000);
var istDate = new Date(istMs);
var hours = istDate.getUTCHours();
var minutes = istDate.getUTCMinutes();
// Convert to total minutes since midnight
var totalMinutes = (hours * 60) + minutes;
var startMinutes = 9 * 60; // 9:00 AM = 540 mins
var endMinutes = 18 * 60; // 6:00 PM = 1080 mins
// Check if email is created between 9 AM and 6 PM IST
if (totalMinutes >= startMinutes && totalMinutes < endMinutes) {
current.type = 'send_ignored'; // Set Type to "Send Ignored"
}
})(current, previous);
If my response helps mark as helpful and accept the solution 🙂
Regards
Sumit
