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

kevin_sherman
Giga Contributor

Hey catchdini,



The issue here is that gs.nowDateTime() returns a timezone-agnostic string of the user's current time, while current.sys_created_on returns a GlideDateTime object that stores its value as a UTC-based datetime plus a timezone. To get around it you can just use the display value, which will account for the user's timezone and format.


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



Kevin


Thanks a lot Kevin. It works perfect now.


Hi kevin,


The script which u suggested is working good ,but it is calculating weekends also.How can i exclude weekends and holidays??


Is there any way to get only days not time..??