The CreatorCon Call for Content is officially open! Get started here.

Auto Close tasks one week after task is triggered consider business days-scheduled job

Gayatrin
Tera Contributor

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..

Gayatrin_0-1692452225731.png

 

 

5 REPLIES 5

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.

 

AnveshKumarM_0-1692711332042.png

 

Thanks,
Anvesh