Auto Close tasks one week after task is triggered consider business days-scheduled job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 06:41 AM - edited 08-19-2023 06:42 AM
Hi all,
I have a requirement that if a task is active & if Assigned to is empty, I need to close the task mark as "Closed Complete" one week after task is triggered consider Business Days (Monday to Friday between 9AM and 5PM) . Please guide. Here is the scheduled job..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 09:06 AM - edited 08-19-2023 09:08 AM
Hi @Gayatrin, the below community solution will help you
Cheers, hope that helps
Eswar Chappa
*** Please mark as "Correct" or "Helpful" as appropriate ***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 11:05 PM
Hi @Gayatrin Please find the below evidence for the Incident for the similar funcationality which was evaluation 7 Business days
var htask = new GlideRecord('sn_hr_core_task');
htask.addEncodedQuery('active=true^assigned_toISEMPTY');
htask.query();
while(htask.next()){
var startDateTime = htask.sys_created_on;
var endDateTime = new GlideDateTime();
var dur = new DurationCalculator();
// Set 9-5 weekday schedule. This is the schedule in which endDateTime, seconds, and totalseconds is set
dur.setSchedule('08fcd0830a0a0b2600079f56b1adb9ae'); //Provide the sys_id of the schedule you use for business days calculation here
dur.calcScheduleDuration(startDateTime, endDateTime);
var businesdays = dur.getSeconds()/(60*60*9);//coverting Business duration time which was in seconds in to days
if(businesdays>7){
htask.setValue('state', '3');//please update the state vlaue of closed here
htask.update();
}
}
Cheers, hope that helps
Eswar Chappa
*** Please mark as "Correct" or "Helpful" as appropriate ***
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2023 10:47 AM
Hi @Gayatrin
You can try replacing your code from line 10 with the following code.
var tskGr = new GlideRecord('sn_hr_core_task');
taskGr.addQuery('active', true);
taskGr.addQuery('assigned_to', '');
taskGr.query();
while(taskGr.next()) {
var createdGdt = new GlideDateTime(gr.sys_created_on.getDisplayValue());
var todayGdt = new GlideDateTime();
var busDur = sched.duration(createdGdt, todayGdt);
var busDurDays = busDur.getDayPart();
if(busDurDays > 7){
taskGr.setValue('state', '3');
taskGr.update();
}
}
Anvesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 04:16 AM
I have tried with this, but it is not running I'm trying to print busDurDays, it's empty.