- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2018 07:14 AM
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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2018 12:35 PM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2018 07:35 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2018 12:35 PM
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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2020 12:37 AM
Hello,
Would you be able to answer this similar question
https://community.servicenow.com/community?id=community_question&sys_id=92bd9c38db5b18903daa1ea66896191d