Sum of Duration fields

Maria DeLaCruz
Tera Guru

Hello,

I am very new to Performance Analytics and need some help.   We tried creating a PA Indicator to get the sum of a duration field of a few thousand records.   For some reason, the dashboard shows 0 for the sum.   Is it possible to add duration fields?   In the screenshot below, the highlighted item is what we want to add up.

Thanks,

Maria

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

pieter_goris
ServiceNow Employee
ServiceNow Employee

Hi Maria,



a duration field is actually a datetime field so you can not simply sum the values from that column but you first need to translate those values to numeric values. In Performance Analytics you can create a script (Data Collector > Scripts) that is called during score collection. For example, a script on the incident table for the field Duration (with a column name of calendar_duration, use that in the actual script) could look like:


        Calendar Duration _ ServiceNow 2016-04-01 22-31-24.png


Durations are stored as offset in milliseconds from Jan 1, 1970; hence the division by (60 * 60 * 1000) to retrieve a number in hours.



Next the script is used when defining the indicator. For example an indicator that retrieves the Average duration of resolved incidents, looks like:



        Average calendar duration of resolved incidents _ ServiceNow 2016-04-01 22-47-32.png



The result looks like:


        ServiceNow 2016-04-01 22-49-56.png



Hope this helps.



Cheers, Pieter


View solution in original post

18 REPLIES 18

pieter_goris
ServiceNow Employee
ServiceNow Employee

Hi Maria,



a duration field is actually a datetime field so you can not simply sum the values from that column but you first need to translate those values to numeric values. In Performance Analytics you can create a script (Data Collector > Scripts) that is called during score collection. For example, a script on the incident table for the field Duration (with a column name of calendar_duration, use that in the actual script) could look like:


        Calendar Duration _ ServiceNow 2016-04-01 22-31-24.png


Durations are stored as offset in milliseconds from Jan 1, 1970; hence the division by (60 * 60 * 1000) to retrieve a number in hours.



Next the script is used when defining the indicator. For example an indicator that retrieves the Average duration of resolved incidents, looks like:



        Average calendar duration of resolved incidents _ ServiceNow 2016-04-01 22-47-32.png



The result looks like:


        ServiceNow 2016-04-01 22-49-56.png



Hope this helps.



Cheers, Pieter


Thanks, Peter!   This worked perfectly!  


Pranav Bhagat
Kilo Sage

Hi All

 

I am getting this error

Error during JavaScript evaluation: Not all references of "current" are passed in by "arguments" script: 

 

Please help

Pranav Bhagat
Kilo Sage

Error during JavaScript evaluation: Not all references of "current" are passed in by "arguments" script:

 

same field is duration only 

var hours = function(){ 
return current.calender_duration.dateNumericValue()/(60*60*1000); 
};

 


hours();