Metric for part of a process

Shannon Burns
Kilo Sage

I'm not sure this is the right place to post this, but I couldn't find a place that fit.

 

I have a metric that tracks when a record moves through different process steps.  That is working fine.

But I need to be able to report on when it spends time in a set of steps that kinda constitute the 'beginning' of the process.  Say I had 7 steps, I want to know how much time it spends in each of steps 1, 2, and 3.

 

BUT the problem is that the name of these steps change all the time.  As such our table that defines them has a field to denote if it is part of the beginning of the process.

 

So how do I write a metric so that it tells me the amount of time spent in each of the steps 1, 2, and 3.  But triggered off of whether the step has beginning = true set for it?

I hope that makes sense.

 

Shannon Burns

2 REPLIES 2

Tanushree Maiti
Tera Sage

Please refer this links, see if it helps you:

 

Calculate state duration 

report on overall incident activity with state changes and assignment group with time stamps 

Write a script to calculate the time taken from new to in progress state of incident and display 

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Shannon Burns
Kilo Sage

I searched before I asked.  Nothing I found seems to fit, or if it does I don't understand how to modify it.

I don't want to use the value to set the metric.  I want to record the value as a metric only if a related field is true.

 

I tried to use this script, and it worked to create one line.  But that was it.  It didn't work for the other steps that are also part of the beginning of the process.

var currentStep = current.process_step;

var grStep = new GlideRecord("x_process_step");
grStep.addQuery("sys_id", currentStep);
grStep.query();

if (grStep.next()) {

    if (currentStep.u_beginning == true)
        createMetric();
}

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

    var gr = mi.getNewRecord();
    gr.value = current.process_step.getDisplayValue();
    gr.start = current.sys_created_on;
    gr.end = current.sys_updated_on;
    gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
    gr.calculation_complete = true;
    gr.insert();
}