Auto Close tasks one week after task is triggered consider business days-scheduled job
Options
- 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..
5 REPLIES 5
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2023 06:36 AM
Hi @Gayatrin ,
I made some mistakes in my script, like variable names. Try with the below script.
var schedRec = new GlideRecord('cmn_schedule');
schedRec.get('name', '8-5 weekdays');
var sched = new GlideSchedule(schedRec.sys_id);
var taskGr = new GlideRecord('sn_hr_core_task');
taskGr.addQuery('active', true);
taskGr.addQuery('assigned_to', '');
taskGr.query();
while(taskGr.next()) {
var createdGdt = new GlideDateTime(taskGr.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();
}
}
I tried this in my PDI and its working, please see the screenshot below.
Thanks,
Anvesh
Anvesh