The CreatorCon Call for Content is officially open! Get started here.

Performance analytics report to calculate duration between to fields

robertmueller
Giga Contributor

Hi,

Can someone advise the script needed in Performance Analytics to calculate the duration between two fields. For example I would like to calculate the duration between when the incident was opened and when it was assigned to someone.

 

Thank you in advance.

1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee
ServiceNow Employee

For time to assignment metrics, I prefer leveraging an SLA since this will allow me to easily calculate business time in addition to absolute time.  Reporting on SLAs is then pretty straight-forward.

If you don't go down this path, you need a Performance Analytics script to perform this calculation per row.  This cannot be done in a Formula since they operate on aggregates.

There should be examples available OOTB based on resolved time.  Just be sure to handle unassigned tasks as well (with score_start) or exclude them from your indicator.  This is the primary use case for Performance Analytics scripts and can also be found in the docs:  https://docs.servicenow.com/csh?version=latest&topicname=pa-scripts

 

View solution in original post

17 REPLIES 17

Adding logic into the reporting is challenging.  The way I normally solve that is with business rules or a scripted metric.  Alternatively, a job to process the data works too.  We want to do the transformations ahead of time so the reports are simple.

Here is a longer explanation of they I take this approach: https://community.servicenow.com/community?id=community_blog&sys_id=2f99990fdbee5b00fece0b55ca9619fb

 

The link is not really what I mean, let me try and clear up. The script below calculates the time between when the ticket was opened and when it was assigned to a Incident Manager (which has a metric table entry). However there is a possibility the field might be updated to someone else, but we would only want to calculate the difference between when it was opened and when it was first assigned, not every time it is assigned. Is this possible without building SLAs via scripts?

 

// Used fields: current.inc_opened_at, current.mi_start
var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var minutes=function(x,y){return diff(x,y)/(60*1000);};
minutes(current.inc_opened_at, current.mi_start);

Atik
Tera Contributor

Thanks its helpful