I am trying to update the duration field for the old tickets(incident and service requests) which are in resolved state. I tried with background script and scheduled jobs but no positive results. Any leads will be appreciated

No NaME
Mega Guru

calculatedura();

function calculatedura() {

  var taskRec = new GlideRecord('task');

  taskRec.addQuery('state', '=', 6);

        taskRec.addQuery('state', '=', 7);

  var orCondition = taskRec.addQuery('sys_class_name', 'incident');

  orCondition.addOrCondition('sys_class_name', 'u_request');

      taskRec.query();

      while (taskRec.next()) {

      var ageInt = gs.dateDiff(taskRec.u_created_at.getDisplayValue(), taskRec.u_resolved.getDisplayValue(), true);

  taskRec.calendar_duration = ageInt;

  taskRec.update();

  }

}

1 ACCEPTED SOLUTION

Abhinay Erra
Giga Sage

Here you go. You need to pass the third parameter as false in gs.dateDiff() function.



calculatedura();




function calculatedura() {


  var taskRec = new GlideRecord('task');


  taskRec.addQuery('state', '=', 6);


        taskRec.addQuery('state', '=', 7);


  var orCondition = taskRec.addQuery('sys_class_name', 'incident');


  orCondition.addOrCondition('sys_class_name', 'u_request');


      taskRec.query();


      while (taskRec.next()) {


      var ageInt = gs.dateDiff(taskRec.u_created_at.getDisplayValue(), taskRec.u_resolved.getDisplayValue(), false);


  taskRec.calendar_duration = ageInt;


  taskRec.update();


  }


}


View solution in original post

8 REPLIES 8

Thanks a ton, It was such a small thing and causing a big issues.



Thanks a lot mate



Cheers!


Now when this script is scheduled, it updated most of the records, but few are not updated. I tried to find out the difference btwn the tickets that got updated and not updated, but no luck. Tried running the script again but its not updating the tickets. Can you please suggest what could be the reason?


abhinay



Now when this script is scheduled, it updated most of the records, but few are not updated. I tried to find out the difference btwn the tickets that got updated and not updated, but no luck. Tried running the script again but its not updating the tickets. Can you please suggest what could be the reason?


No NaME
Mega Guru

Now when this script is scheduled, it updated most of the records, but few are not updated. I tried to find out the difference btwn the tickets that got updated and not updated, but no luck. Tried running the script again but its not updating the tickets. Can you please suggest what could be the reason?