NEW METRIC DEFINITION APPEARS TO NOT WORK

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-18-2024 06:02 AM - edited 09-18-2024 08:42 AM
Hello. I need help because I know I am not doing something correctly. I created a new metric definition called "Create To Staff Assignment" where the goal is to record metric record from the time the INC is created and up to the time the assigned to field is valued.
Below is the metric definition. The following code below the screen shot is the business rule. As shown in the lower part of the screen shot of the metric definition record, the metric created records the start date of when I updated the INC to add an assigned to value. I am wondering what am I missing given that there was already a metric definition for the same field I am trying to measure with the same type as shown by the screen shot after the new metric definition I created.
Would love to get some help to make this work. Thank you all.
New Metric Definition Record
Metric Definition List on INC
Business Rule
Script in the business rule
- Labels:
-
Architect

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-19-2024 08:24 AM
@Anantha Gowrara . Just another input. If I use the type script calculation, the metric_instance record is NOT created. If I set the type to field value calculation, the metric_instance record is created with the start date filled in and the rest is empty. It appears like there is an event waiting for the INC to be resolved or closed? Where do I find this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 07:08 PM
// variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)
var createdDate = new GlideDateTime(current.sys_created);
// Find the first assignment
var firstAssignment = new GlideRecord('incident');
firstAssignment.addQuery('sys_id', current.sys_id);
firstAssignment.addQuery('assigned_to', '!=', '');
firstAssignment.setLimit(1);
firstAssignment.query();
// If a first assignment is found, calculate the duration
if (firstAssignment.next()) {
// var assignedDate = new GlideDateTime(firstAssignment.assigned_to);
// var tDuration = GlideDateTime.subtract(assignedDate, createdDate);
// current.metric_value = tDuration.getDecimal();
createMetric();
}
//createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.sys_created_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-24-2024 07:07 PM
I made it work with the following code
// variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)
var createdDate = new GlideDateTime(current.sys_created);
// Find the first assignment
var firstAssignment = new GlideRecord('incident');
firstAssignment.addQuery('sys_id', current.sys_id);
firstAssignment.addQuery('assigned_to', '!=', '');
firstAssignment.setLimit(1);
firstAssignment.query();
// If a first assignment is found, calculate the duration
if (firstAssignment.next()) {
// var assignedDate = new GlideDateTime(firstAssignment.assigned_to);
// var tDuration = GlideDateTime.subtract(assignedDate, createdDate);
// current.metric_value = tDuration.getDecimal();
createMetric();
}
//createMetric();
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.start = current.sys_created_on;
gr.end = current.sys_updated_on;
gr.duration = gs.dateDiff(gr.start.getDisplayValue(), gr.end.getDisplayValue());
gr.calculation_complete = true;
gr.insert();
}