
Mike Patel
Tera Sage
Options
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 05-11-2019 05:50 PM
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();
}
- 1,874 Views
Comments
Laukik Udpikar
Tera Expert
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
08-27-2020
02:49 AM
Hi Mike,
What is the sys_id in line 10.

Mike Patel
Tera Sage
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
08-27-2020
05:07 AM
That is the sys_id of the schedule that I wanted to use.