Calculate amount of time between 2 states

codedude
Mega Expert

I would like to calculate the amount of time between when the user opens a ticket and when that ticket is closed. The state it is set to when created is Opened and the state when it is closed, you guessed it, it's Closed. So I am in need in getting the amount of time the ticket was open....

Example: ticket was opened at 8:00 AM closed at 9:00 AM. So the field would need to read 1 hour.... I have seen the duration field, how can i calculate this in that field?

1 ACCEPTED SOLUTION

I would instead recommend using METRICS as that is their point.   TO measure that kind of stuff.


View solution in original post

3 REPLIES 3

Jace Benson
Mega Sage

I don't think having a field for that calculation is the best use of a field but if you must here's what you would need to do.


To get that duration you would need to know when it was opened.   That is currently stored in incident.sys_created_on.


With that information, you can then add a before business rule to run when the state.changesTo('numberforclosedstate');


It would need some code to get the duration.



So in short try this replacing the the duration field to the field you want;



//Condition


//current.state.changesTo('numberforclosedstate');


//Script


current.duration_field = gs.dateDiff(current.sys_opened_at.getDisplayValue(), gs.nowDateTime(), false);


I would instead recommend using METRICS as that is their point.   TO measure that kind of stuff.


Victor Ruiz
Tera Guru

You can use the business_duration field on INC then in the mark_closed BR comment out the section shown below.   This will give you the time stamped by the mark_resolved BR.




3.JPG



2.JPG


1.JPG