Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Using metrics to track number of field changes

Wade Williams
Giga Contributor

I've got a requirement (currently using London) which I believe is a simple use of metrics, however I'm not finding any relevant examples and I haven't done a lot with metrics yet so the answer isn't jumping out at me.  Most of the examples revolve around reporting on a field change duration.

Requirement 1:

Report on how often someone is changing the Urgency field in any incident from Low to High or vice-versa.  i.e. how many times a week is someone changing an incident in this way?  A month?

Requirement 2:  

Be able to breakdown the number of changed incidents by who is changing them

Any pointers would be greatly appreciated. Or better yet, steps I can duplicate in a development instance.

3 REPLIES 3

Michael Fry1
Kilo Patron

If you want to capture all changes to Urgency, you can just build a simple Field value duration metric like below:

 

find_real_file.png

 

If you want to capture only 1 -> 3, or 3 -> 1, then you will need to add a script to the Metric to check the value and if true, then capture the metric.

Michael,

 

Thanks for the response.  Could you provide a bit of sample code for checking the urgency value and then capturing the metric?  I've not found much in the way of relevant sample code.

Something like this should work:

 

if (current.urgency != '2')
        createMetric();


function createMetric() {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return;

  var gr = mi.getNewRecord();
  gr.field_value = true;
  gr.calculation_complete = true;
  gr.insert();
}