- If the incident is re-opened while in a resolved state, a new metric created

sujaykm
Tera Contributor

If the incident state changes to resolved, new metric has been creating, 
If the incident is re-opened while in a resolved state new metric should create

 

if (current.state == 6) {
    createMetric();
}

function createMetric() {
    var gr = mi.getNewRecord();

    gr.start = current.sys_created_on;
    gr.end = current.sys_updated_on;

    var start = new GlideDateTime(gr.start);
    var end = new GlideDateTime(gr.end);
    gr.value = "Test";
    gr.duration = gs.dateDiff(gr.start, gr.end);
    gr.calculation_complete = true;
    gr.insert();

}
right now i am using this code for "If the incident state changes to resolved, new metric has been creating,"
 
can u modify the code for "If the incident is re-opened while in a resolved state new metric should create" this also
2 REPLIES 2

Mark Manders
Giga Patron

This is already taken care of OOB. Every state change creates a new metric record.

 

Also: posting the same question twice is against Community guidelines:

https://www.servicenow.com/community/community-resources/servicenow-community-code-of-conduct-for-al...
https://www.servicenow.com/community/developer-forum/if-the-incident-is-re-opened-while-in-a-resolve...


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

joe806root
Kilo Contributor

In ServiceNow Metric Definitions, the script usually runs when the record is updated. To capture a "re-open," we look for a change where the previous state was "Resolved" (6) and the current state is anything else (like "In Progress" or "New").