- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 08:59 AM
Hi All,
Good evening to all.
I had a requirement to notify the problem manager prior to 2 days based on the due date. The below script of mine is working as expected.
My schedule job script below:
Script name : Problem Task Due date Reminder two days
queryPlannedDate();
function queryPlannedDate(){
var qrystr = "active=true^due_date>javascript:gs.daysAgoEnd(-1)^due_date<javascript:gs.daysAgoEnd(-2)";
var expdt = new GlideRecord('problem_task');
expdt.addEncodedQuery(qrystr);
expdt.query();
while(expdt.next()){
gs.eventQueue('problem_task.duedate1', expdt, expdt.assigned_to);
}
}
This script will execute on daily basis. It is working fine. Now the user tweaked the request and he wants exclude the week end(saturday and sunday). If the Problem task due is on Monday, The script should skip the saturday and sunday and fire on thursday( 2 days prior excluding weekends ). If the problem task due date is on Tuesday, This script will trigger on Friday.
Is there a way I can modify my script or any suggestions would be of great help because I have no clue on how to exclude weekends from the script.
Note : the above script is running based on al calendar days.
Thanks
Kamal
Solved! Go to Solution.
- Labels:
-
Problem Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 04:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 11:46 AM
I see that you have already created a schedule 24/5, which is good.
Now all you need is find the Due Date of Problem_task that is 2 days from the current date(Excluding weekends). If you have created the schedule with out errors, then use the below code snippet to get the required DueDate which is two days after the current date according to your schedule.
var dur = new GlideDuration('2 00:00:00');//Days HH:MM:SS - i set it to 2 days
var now = new GlideDateTime();
var sched = new GlideSchedule();
sched.load("08fcd0830a0a0b2600079f56b1adb9ae"); // Sys_id of your 24/5 schedule, i set it to 8-5 weekdays
gs.print(sched.add(now,dur)); // this will spit out the due date that is after 2 days excluding the weekdays
Once you get the required due_date, proceed with the event and notification logic.
Please mark the answer correct/Helpful if applicable so that it will help others in future.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 03:07 PM
Hi Aman,
I have added those mentioned lines in my script in scheduled job.
/*var gr = new GlideRecord('cmn_schedule');
if (gr.get('name', '24-5 weekdays excluding holidays')) {
var schedule = new Packages.com.glide.schedules.Schedule(gr.sys_id);
if(schedule.isInSchedule(new GlideDateTime())) {
queryPlannedDate();
}
} */
var dur = new GlideDuration('2 00:00:00');//Days HH:MM:SS - i set it to 2 days
var now = new GlideDateTime();
var sched = new GlideSchedule();
sched.load("032bd165db8ce7808567fd7aae961998"); // Sys_id of your 24/5 schedule, i set it to 8-5 weekdays
gs.print(sched.add(now,dur)); // this will spit out the due date that is after 2 days excluding the weekdays
queryPlannedDate();
function queryPlannedDate(){
var qrystr = "active=true^due_date>javascript:gs.daysAgoEnd(-1)^due_date<javascript:gs.daysAgoEnd(-5)";
var expdt = new GlideRecord('problem_task');
expdt.addEncodedQuery(qrystr);
expdt.query();
while(expdt.next()){
gs.eventQueue('problem_task.duedate1', expdt, expdt.assigned_to);
}
}
I have created Problem task PTASK0010493 and Due date is 2018-08-27 17:42:50 (Next Monday). I have skipped the weekend(used due_date<javascript:gs.daysAgoEnd(-5))
Ran the scheduled Job and check the emails logs email notification is not triggered.
Please check the above script and Suggest me ?
Thanks,
Kamal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-20-2018 04:00 PM
You are not comparing the DueDate we got from the schedule.
Try the below script.
var dur = new GlideDuration('2 00:00:00');//Days HH:MM:SS - i set it to 2 days
var now = new GlideDateTime();
var sched = new GlideSchedule();
sched.load("032bd165db8ce7808567fd7aae961998"); // Sys_id of your 24/5 schedule, i set it to 8-5 weekdays
var required_dueDate = sched.add(now,dur);
queryPlannedDate();
function queryPlannedDate(){
var expdt = new GlideRecord('problem_task');
expdt.addQuery("active",true);
expdt.addQuery("due_date","STARTSWITH",required_dueDate.getDate());
expdt.query();
while(expdt.next()){
gs.log("Dead Line appraoching for the Problem "+expdt.getValue('number'));
gs.eventQueue('problem_task.duedate1', expdt, expdt.assigned_to);
}
}
Let me know if it worked. If you still did not get any notifications, then go to script log statements and check for messages that contain Dead Line approaching for the Problem. I put a Log statement in the code.
If you find any Log statements, check if the log statements contain appropriate Problem numbers. Let us know the results
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 03:28 AM
Hi Aman,
Existing Scheduled job script Inactivated. I have created new Scheduled job and using the above script.
Scheduled Job Name : Problem Task Due date Reminder two days Testing
Please find the attached screenshots in this post. All I have attached here.
I have created Problem task on various due dates
i.e.,
PTASK0010494 --> Due 23/08
PTASK0010495 --> Due 28/08
PTASK0010496 --> Due 24/08
I ran the scheduled job(Problem Task Due date Reminder two days Testing). After i checked email logs in Dev environment. I able to see the this PTASK0010494 --> Due 23/08. It is correct. Working fine.
I want to test exclude weekends. How Should I test it ?
Suppose my due is on 28/Aug/2018(next week tues day).. The email needs to trigger on Friday(24/Aug/2018).
Exclude weekend.
Should I test the scenario today or should I wait until friday?
Please Suggest me.
Thanks,
Kamal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-21-2018 04:36 AM