Indicator 'Time by state' for demand

Leonel Sandroni
Tera Guru

I want to build an indicator that shows the average time (days or hours) that demands are in each state. The purpose is to identify bottlenecks in the demand's flow. Performance Analytics only have indicators with the entire time (from start to end) but it doesn't show by state.

1 ACCEPTED SOLUTION

Hi Leonel,

While process optimization is the more sophisticated tool, you could also create a metric defintion that tracks how much time the demand record is in each state. It would be identical to the OOTB Incident State metric definition, just changing the table and the field values

Dan_Kane_0-1682364096197.png

Note that metrics are only captured after the metric definition is defined and activated, so it would not get data from demands created before the metric was activated.

View solution in original post

9 REPLIES 9

Amit Gujarathi
Giga Sage
Giga Sage

Hi @Leonel Sandroni ,
I trust you are doing great.
Follow the below steps for the answer :

  1. Create a Performance Analytics widget To get started, we'll need to create a new Performance Analytics widget. In the Performance Analytics Workspace, navigate to the Widgets tab and click the "New" button. From there, select the "Indicator" widget type.

  2. Add a data source that retrieves the duration of time that demands are in each state Next, we'll need to add a data source that retrieves the duration of time that demands are in each state. We can do this using a scripted data source. Here's an example script that you can use as a starting point:

 

var gr = new GlideRecord('demand');
gr.addQuery('active', true);
gr.query();

var results = {};

while (gr.next()) {
  var state = gr.getValue('state');
  var duration = gs.dateDiff(gr.getValue('sys_created_on'), gr.getValue('sys_updated_on'), true);

  if (!results[state]) {
    results[state] = {
      total_duration: duration,
      count: 1
    };
  } else {
    results[state].total_duration += duration;
    results[state].count++;
  }
}

return results;

 

This script retrieves all active demands and calculates the duration of time that each demand is in each state. It then aggregates the results by state and returns an object that looks like this:

 

{
  'State 1': {
    total_duration: 1234,
    count: 10
  },
  'State 2': {
    total_duration: 5678,
    count: 20
  }
}

 

  1. Use scripting to calculate the average time for each state Now that we have our data source, we can use scripting to calculate the average time for each state. Here's an example script that you can use:

 

var results = data.result;
var averages = {};

for (var state in results) {
  var total_duration = results[state].total_duration;
  var count = results[state].count;
  var average_duration = total_duration / count;

  averages[state] = average_duration;
}

return averages;

 

  1. Display the results in the widget Finally, we can display the results in our Performance Analytics widget. To do this, we'll need to add a "Data" source to the widget and select our scripted data source. We can then add a new "Formula" metric and use our second script to calculate the average time for each state.

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



Maybe this is a solution. Is the last script write in the right way? I tried with it but it doesn't work. 

Jeroen van Gass
ServiceNow Employee
ServiceNow Employee

An ideal way to measure and identify these bottlenecks is to use our in-platform process mining solution "Process Optimization" https://www.youtube.com/watch?v=a9eQNx3tegc 

 

To understand how PA and PO complement each other I would recommend to read: https://www.servicenow.com/community/process-optimization-article/how-do-process-optimization-and-pe...

 

Jeroen

 

It's a perfect solution! but we should pay for the plugin. Do you know about a workaround?