Calculating the time and incident has been open for

Dubz
Mega Sage

Hi All,

One of our managers wants to be able to produce a list of incidents and have a field there for each one saying how long it has been open for. What's the best way to go about this?

I thought the easiest way to do this would be to add a new field to the incident form and add in the calculated value something like:

var opened = current.opened_at.getDisplayValue();

var now = gs.nowDateTime();

var time = gs.dateDiff(opened, now, true);

My first question is, what performance effect (if any) will this have if it is calculating this value for every incident? If it's going to have a knock on performance issue would i be better off making this a metric instead?

If it isn't going to effect performance, how do i present the resulting seconds in a days/hours/minutes/seconds time field?

1 ACCEPTED SOLUTION

Uncle Rob
Kilo Patron

Hey David,



The problem with Calculated fields is that they don't perpetually calculate in real time.   The only calculate on a create or update.   Thus you'll never get the "time open" but rather "the amount of time this was open the last time I saved it".



This use case is really best supported by Performance Analytics, where your management would simply look at the oldest tickets (and the pattern of age) and drill in from there.  


View solution in original post

21 REPLIES 21

Uncle Rob
Kilo Patron

Hey David...



What do you think of this?   Would this work?



find_real_file.png


Ha, that's just a user preference right?! That might just work you know! i'll pitch that before i go messing about with metrics. Thanks Robert!


If you *do* go messing with Metrics there's a critical missing component:   Durations always populate *after*


The one time I did something like this, I created a business rule that would run every 4 hours, that would query all non-complete metric instances, then insert a duration measured from the MI creation time to currentdatetime.   That way you were always accurate up to a 1/2 day on metrics that were currently "running".



Even if you nail that, you've still got the issue that the data's now in the metric instance table, not the Incident table... so you'll likely also need a Database View.   All for one person's view preference.



Some other options (besides the User Preference "days ago")


- Personalized list view with Opened / Updated columns and just deal with sorting


- A homepage with "score" report types where each score has a time range (over 3 weeks / 1-3 weeks / 1-5 days / <24 hurs)


Sounds like i'm going to have to investigate just who this guy is and what influence he may or may not have over my long-term career prospects


Hey David,



Whomever he may be, I think he'd appreciate a deeper discussion.   In my experience "show me the data this way" is the attempted scratch of an itch.
What's really bothering him is the itch, not the specific scratching method.   Go full on Simon Sinek on him:   "totally understand what you want.. but can you tell me why"



You might get an answer like "my business stakeholders are pissed that my tickets take too long"
"what's too long"?
"XXXXXX"
Report with tickets that are over XXXX or under XXX by a YYY threshold.   Problem solved.




That's just one possibility, but it more precisely applies your clearly capable ServiceNow skill.