Ticket age calculation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2014 01:23 AM
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();
}
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.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2014 11:45 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2014 03:41 AM
Thanks a lot Kevin. It works perfect now.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2015 10:55 PM
Hi kevin,
The script which u suggested is working good ,but it is calculating weekends also.How can i exclude weekends and holidays??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2015 08:39 AM
Is there any way to get only days not time..??