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
10-14-2015 10:25 AM
Any answer to this question. I want stright natural days also
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2015 11:11 PM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015 11:37 AM
Hello Gayathri,
Were you able to figure out how to exclude weekends on your calculation? Do you mind sharing?
Thanks,
Edwin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015 12:24 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-08-2015 12:58 PM
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