- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 10:11 PM
Hi,
I am working on requirement from user to trigger a notification to user three working days before due date, next working day after due date, four working days after due date, and five working days after due date and it should not trigger a notification on weekends.
I have created one Scheduled Job script but that is working for calendar days and not for working or business days.
below is my written script,
var gr = new GlideRecord("sn_lg_ops_request");
gr.addEncodedQuery("state=8^active=true");
gr.query();
while (gr.next()) {
gs.info("This is the check");
var due_date = gr.u_inprinciple_complete_due_date;
var current_date = new GlideDate();
var now = new GlideDateTime();
var due = new GlideDateTime(due_date);
// Calculate the difference in days
var diff = now.getNumericValue() - due.getNumericValue();
var diffdays = diff / (1000 * 60 * 60 * 24);
gs.info("The diff is:" + Math.round(diffdays) + ":" + gr.number);
// Trigger events based on the difference in days
if (due_date < current_date) {
// Already past the due date
if (Math.round(diffdays) == 1) {
gs.eventQueue('sn_lg_ops.inprincipleduedate', gr, '', '');
}
if (Math.round(diffdays) == 4) {
gs.eventQueue('sn_lg_ops.inprincipleduedate', gr, '', '');
}
if (Math.round(diffdays) == 5) {
gs.eventQueue('sn_lg_ops.inprinciplefifthdayafterdue', gr, '', '');
}
} else {
// Future due date; check for three days before the due date
if (Math.round(diffdays) == -3) {
gs.eventQueue('sn_lg_ops.inprinciple3daysbeforeduedate', gr, '', '');
}
gs.info("This is not to trigger: " + gr.number);
}
}
can anyone help me on this issue,
Thanks in Advance.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 11:18 PM - edited 11-13-2024 11:27 PM
Hi @devendra9 ,
If you want to prevent this logic from executing on the weekend days you can use the GlideDateTime().getDayOfWeekUTC() method to see which day it is. In your script you can create a variable that keeps track of the fact wether today is a weekend day or not and prevent executing the gs.eventQueue calls.
var dayOfWeek = now.getDayOfWeekUTC();
var isWeekend = ( dayOfWeek == 6 || dayOfWeek == 7);
Best regards,
Joni
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-13-2024 11:18 PM - edited 11-13-2024 11:27 PM
Hi @devendra9 ,
If you want to prevent this logic from executing on the weekend days you can use the GlideDateTime().getDayOfWeekUTC() method to see which day it is. In your script you can create a variable that keeps track of the fact wether today is a weekend day or not and prevent executing the gs.eventQueue calls.
var dayOfWeek = now.getDayOfWeekUTC();
var isWeekend = ( dayOfWeek == 6 || dayOfWeek == 7);
Best regards,
Joni