Mike Patel
Tera Sage

Scheduled Job to calculate Business Duration and Duration field on TASK. It can be used for other task types just by change encodedquery.

var gr = new GlideRecord('task');
gr.addEncodedQuery('active=false^calendar_durationISEMPTY');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
	var gdt1 = new GlideDateTime(gr.sys_created_on.getDisplayValue());
	var gdt2 = new GlideDateTime(gr.closed_at.getDisplayValue());
	var dur = gs.dateDiff(gdt1, gdt2, false);
	gr.calendar_duration = dur;
	var gsBusiness =new GlideSchedule('090eecae0a0a0b260077e1dfa71da828'); //sysid of schedule
	// Get duration based on schedule
	gr.business_duration = gsBusiness.duration(gr.sys_created_on.getGlideObject(), gr.closed_at.getGlideObject());
	gr.setWorkflow(false);
	gr.update();
}

find_real_file.png

Comments
Laukik Udpikar
Tera Expert

Hi Mike,

What is the sys_id in line 10.

Mike Patel
Tera Sage

That is the sys_id of the schedule that I wanted to use.

find_real_file.png

Version history
Last update:
‎05-11-2019 05:50 PM
Updated by: