How to calculate age of an incident

sk59
Tera Expert

Hi All,

Is there any OOB field which stores the duration of an incident. I could see 'Duration' field but it calculates once the incident is resolved. I would like to find out age of the incident from incident creation.

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

There is no direct OOB feature that is available other than the duration field. You shall use duration field which calculates on resolve or use the code that calculates during resolve and store it in your custom field.

Mark the comment as a correct answer and helpful if it answers your question.

View solution in original post

4 REPLIES 4

Dubz
Mega Sage

You could create a metric that tracks the time from when the ticket was opened to the time now but i'm not sure what the value of this would be. 

I think you'd be better off using the standard duration field to report on the duration of incidents once they've been closed and use an SLA to track how long a ticket has been active and report on incidents that breach your SLA conditions.

Jaspal Singh
Mega Patron
Mega Patron

Hi,

 

There does not exist any OOB feature to calculate age from creation irrespective of current state. If required an additional field can be created & below snippet (untested) can be used to calculate the age of incident from its creation in the form of Scheduled job.

 

var datecreated=gr.sys_created_on;
gs.log('Date created is ',datecreated);
var datenowis=gs.nowDateTime();
gs.log('Current date time is ',datenowis);

var gr = new GlideRecord("incident");
gr.addQuery('number','INC0012686'); //try pasing any random incident number for check
gr.query();  
while (gr.next()) {  
var datediffis= gs.dateDiff(datecreated,gs.datenowis,true);
gs.log('Date diff is ',datediffis)
gr.u_age= datediffis; //Considring u_age is the dictonary value for Age field  
gr.update();  
}  

 

Thanks,

Jaspal Singh

 

Hit Helpful or Correct on the impact of response.

asifnoor
Kilo Patron

Hi,

There is no direct OOB feature that is available other than the duration field. You shall use duration field which calculates on resolve or use the code that calculates during resolve and store it in your custom field.

Mark the comment as a correct answer and helpful if it answers your question.

Ranjith95
Tera Contributor

step 1: Create a field "incident age" of Duration type

step 2: open the dictionary of the field and apply below code in "calculated value" tab

 

(function calculatedFieldValue(current) {

    // Add your code here
    var sd = new GlideDateTime(current.getValue('sys_created_on'));
    var ed = new GlideDateTime();
    var dur = GlideDateTime.subtract(sd,ed);
    return dur;
    //return dur.getDayPart();
    // return the calculated value

})(current);
 
Please mark it as helpful if the solution is applied.