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.

Change Request metric

Swapnil Meshram
Mega Guru

Hi Experts,

I want to create change metric for reporting purpose.How to calculate the duration from authorize state to implement state by using change metric.

Thanks 

 

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

Create a script metric on the change request table with the following script:

authorizetoimplement(definition, current);

function authorizetoimplement(definition, current){
    var s = current.state;
    var mi = new MetricInstance(definition, current);
    if (mi.metricExists()) {
        if (s == -1) {
            mi.endDuration();            
        }
    } else if (s == -3) {
        mi.startDuration();
    }
}

View solution in original post

3 REPLIES 3

rammohanraomadd
Kilo Guru

Hi,

 

When we create a metric, every time state change a new record will be created. Instead create a custom field (duration) and calculate the time when state changes and add the duration to the field.

 

Regards,

Ram M

Michael Fry1
Kilo Patron

Create a script metric on the change request table with the following script:

authorizetoimplement(definition, current);

function authorizetoimplement(definition, current){
    var s = current.state;
    var mi = new MetricInstance(definition, current);
    if (mi.metricExists()) {
        if (s == -1) {
            mi.endDuration();            
        }
    } else if (s == -3) {
        mi.startDuration();
    }
}

Deepansh Jain
Kilo Contributor

Hello,

Would you be able to answer this similar question

 

https://community.servicenow.com/community?id=community_question&sys_id=92bd9c38db5b18903daa1ea66896191d