Can i create Metric Instance on TASK ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 10:27 AM
Hello,
We have a requirement where we need to pull a report of all users how much time user spent on tickets on table like Incident, Problem. I can use OOB Metric instance for user record but how to set for Problem table ???
Please help me on this...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 11:38 AM
Hi Shaik,
You should be able to, here's an example of what I did for metrics when the state of the demand changes.
/*
* Metrics for tracking the changing state of demands.
*/
// If this is a new record, then create a
// metric record.
if (current.sys_created_on == current.sys_updated_on) {
createMetric();
// If the record is active, the previous
// metric needs to be closed and the next
// one needs to be created.
} else if (current.active) {
closeMetric();
createMetric();
// If the record is inactive, the previous
// metric needs to be closed and the final
// one needs to be created and then closed.
} else if(!current.active) {
closeMetric();
createMetric();
closeMetric();
}
/*
* Create a metric.
*/
function createMetric() {
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
gr.field_value = true;
gr.start = current.sys_updated_on;
gr.calculation_complete = false;
gr.insert();
}
/*
* Close a metric.
*/
function closeMetric() {
var gr = new GlideRecord('metric_instance');
gr.addQuery('id', current.sys_id);
gr.addQuery('calculation_complete', false);
gr.addQuery('definition.type', 'calculation');
gr.query();
if (gr.next()) {
var definition = new GlideRecord('metric_definition');
definition.get(gr.definition);
var mi = new MetricInstance(definition, current);
mi.endDuration();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 10:51 PM
Thanks for the script Frank.
can you please let me know where should i write this scrpt ???
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2018 08:03 AM
Sorry, just saw the message. It goes in Definitions under Metrics.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2018 11:43 AM
Are you using the Time Worked field on tasks? (incident form, Problem form, etc) If yes, this will capture time worked on every save. Then you can report off of time worked.