BR or background script to set record duration

chrisn_
Mega Guru

I have created a custom table with task records on it that I want to create certain statistics for that we have in incident. One big one is the duration of the record from start to finish. I am currently trying to run a job to do this for existing records, but I also want to set this up going forward. I have tried emulating the mark for closure BR that runs on incident but I couldn't get it to work, can someone please help me identify where I have gone wrong with this background script to start? 

var gr = new GlideRecord("x_unoci_graduate_d_graduate_division"); <--(my custom table)
gr.addEncodedQuery('active=false^calendar_durationISEMPTY');
gr.query();
var dur = new DurationCalculator();
dur.setSchedule('090eecae0a0a0b260077e1dfa71da828');  <---(the schedule our instance uses)
gr.calendar_duration = dur.calcScheduleDuration(startdatetime, enddatetime);
while(gr.next()) {
    gr.calendar_duration = dur;
    gr.setWorkflow(false); 
    gr.update();
}
5 REPLIES 5

Check out the following community post for possible alternative:

Use DurationCalculator in scoped application