Ticket age calculation

catchdini
Tera Expert

I created a business rule (on display) for incidents, to calculate the age. Below is the BR that I used. I created 2 fields - Age and Current Date(though I didn't use this for calculation). Current Date is obtained by a BR (on display) with the script current.u_current_date = gs.nowDateTime();

 

I have included 2 var in the script, where one is commented. If the current date field is utilized then one can make use of the commented var. If current date field is not utilized, then one can use the other var.

 

calculateAge();

function calculateAge(){

var datedif = gs.dateDiff(current.sys_created_on,gs.nowDateTime());

//var datedif = gs.dateDiff(current.sys_created_on,current.u_current_date);

current.u_age = datedif;

current.update();

}

 

find_real_file.png

 

Though Im seeing the Age, Im not sure how the difference (not sure which time zone is utilized ) is calculated. Hope this is the answer for everyone who wanted to calculate the age. If there is anything wrong in the calculation, please let me know.

13 REPLIES 13

Any answer to this question. I want stright natural days also


I wrote this script include for calculating ticket age pending for approval and its just giving you date, hope this will help you



function AutoApprovalEmailNotification() {


      var gr = new GlideRecord('sysapproval_approver');


      //gr.addQuery('state', 'requested');


      gr.addEncodedQuery('sysapproval.sys_class_name=change_request^ORsysapproval.sys_class_name=sc_req_item^state=requested');


      //gr.setLimit(2);


      gr.query();


      while(gr.next()){


              var datedif = gs.dateDiff(gr.sys_created_on,gs.nowDateTime());


              var datetrim=datedif;


              var index=datedif.indexOf(' ');


              var aftertrim=datetrim.substring(0,index);


             


              gr.u_approval_ticket_age = aftertrim;


              gs.print(aftertrim);


              gr.update();


      }


}


etobia
Kilo Expert

Hello Gayathri,



Were you able to figure out how to exclude weekends on your calculation? Do you mind sharing?



Thanks,


Edwin


Hey edwin,


You can use a calendar combined with the calDateDiff function (takes the same arguments as the script I posted up above, but with a calendar that you can exclude weekends and holidays and such with).



Kevin


Hi Kevin,



Thanks for the reply back. Would you be able to provide steps on what you are recommending? Not quite sure where to begin when you say use a calendar combine with calDateDiff funciton.



Thanks in advance!



Edwin