Notification - Advanced Condition
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 07:33 PM
The following notification below was created to send a notification if a case is created with the conditions below. What we what, is to send a notification if a case is created between Friday @8:30pm (which is 06:00am IST) and Sunday @8:30pm (which is 06:00am IST). However, a notification was sent when a case was created at 04:51am Monday. Which is outside the time period. I'm sure we need to update the Advanced Condition script below, but not what to change.
//Created between 06:00am IST (8:30pm EST) Saturday and 06:00am IST (8:30pm EST) Monday.
answer = false;
var created_on = new GlideDateTime(current.getDisplayValue('sys_created_on'));
var date = created_on.toString().split(' ')[0];
var time = created_on.toString().split(' ')[1];
var initialTime = new GlideTime();
initialTime.setValue('20:30:00');
initialTime = initialTime.toString().split(' ')[1];
var endTime = new GlideTime();
endTime.setValue('20:30:00');
endTime = endTime.toString().split(' ')[1];
//Get weekday:
//1 = Monday; 6 = Saturday; 7 = Sunday
var week_day = created_on.getDayOfWeekLocalTime();
if (week_day == 7) {
answer = true;
} else if (week_day == 6) {
if (time > initialTime) {
answer = true;
}
} else if (week_day == 1) {
if (time < endTime) {
answer = true;
}
} else {
answer = false;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 08:14 PM
Hi, GlideDateTime getDisplay() value will return the date\time in the time-zone of the logged in user, IE the user triggering the script and so if this varies then the result\outcome will vary.
GlideDateTime | ServiceNow Developers
If the time window is fixed and not subject to any localized daylight savings,
then you should be able to use getValue() and map\align the window with UTC to ensure correct and consistent results.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 09:05 PM
HI @MStritt ,
I trust you are doing great.
To address the issue of sending notifications outside the desired time period, we need to modify the Advanced Condition script provided. Below is the updated code:
answer = false;
var created_on = new GlideDateTime(current.getDisplayValue('sys_created_on'));
var week_day = created_on.getDayOfWeekLocalTime();
var time = created_on.getTime();
// Saturday: 6, Sunday: 7
if (week_day == 6 || week_day == 7) {
var start_time = new GlideDateTime();
start_time.setDisplayValue(created_on.getDate().toString() + " 06:00:00");
var end_time = new GlideDateTime();
end_time.setDisplayValue(created_on.getDate().addDays(1).toString() + " 06:00:00");
if (created_on.compareTo(start_time) >= 0 && created_on.compareTo(end_time) <= 0) {
answer = true;
}
}
current.u_send_notification = answer;
Was this answer helpful?
Please consider marking it correct or helpful.
Your feedback helps us improve!
Thank you!
Regards,
Amit Gujrathi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2023 09:15 PM
Hi Amit,
Thanks for your reply. The notification will be triggered in EST time. So, we want the notification to be sent if a case is created anytime between 8:30pm EST (20:30) Friday and 8:30pm EST (20:30) Sunday.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2023 08:30 AM
Hi Amit,
The 06:00 IST time really is irrelevant I guess. Since the notification will trigger off EST time, can you update the script to show the notification will be sent if a case is created between Friday 8:30pm/20:30 EST time and Sunday 8:30pm/20:30 EST time?