Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Metric definition script to calculate custom table state duration

Mabubi
Tera Contributor

HI,

 

Can any one help here to calculate the custom table state duration .

 

The condition should be state changes then metric instance  should created & then state changes to another state metric  instance should be closed ,calculate the state duration ,the new state metric instance should be create same the flow.

 

I have state values multiple states like 20 choice.

 

currently am doing this below script but it will work only one state to another state changes. I need to include all state values to be include in one metric definition script..can you let me know please

 

 

Script:

    if (current.u_status.getDisplayValue() == "Received" ) {
        createMd();
    } else if (current.u_status.getDisplayValue() == " Search") {
        closeMd();
    }

    //calls the script include "MetricInstance" and create a metric instance
    function createMd() {
        var md = new MetricInstance(definition, current);

        //  check if a metric instance exists already
        if (md.metricExists()) {
            return;
        }
        var gr = md.startDuration();
    }

    //calls the script include "MetricInstance" and close the metric instance
    function closeMd() {
        var md = new MetricInstance(definition, current);

        if (md.metricExists()) {
            md.endDuration();
        }
    }

 

 

1 REPLY 1

Uncle Rob
Kilo Patron

Have you looked at the OOB "Open" metric for Incidents?  It does something similar.

UncleRob_0-1732556643896.png