- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 10:22 AM
Hello All,
I'm trying to create a metric definition on task table, on assigned to field. But my matric should only calculate where assignment group is "Prep Group". I believe type should be script calculation duration. could anyone help me with what I'm doing wrong in this code.
if (!current.active) {
if (current.assignment_group == 'PREP group Sys_id')
createMetric();
}
function createMetric() {
var mi = new MetricInstance(definition, current);
if (mi.metricExists())
return;
var gr = mi.getNewRecord();
gr.field_value = value;
gr.calculation_complete = true;
gr.insert();
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2025 02:59 AM
I would be careful with directly querying sys_audit because of the impact on performance.
Try the following
answer = (function(mi){
var incidentGR = mi.current;
//Hard-coding sys-id to Help Desk for testing purposes
if(incidentGR.getValue('assignment_group') != '679434f053231300e321ddeeff7b12d8'){
//End the existing duration field
mi.endDuration();
//Don't allow the creation of a new metric instance
return false;
}
return true;
}(mi))
This works in my PDI - it'll create a metric for the assigned to as long as the assignment group is the sys_id I've specified. If it's not, it'll stop the metric

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 12:46 PM
What are you wanting to calculate? How long it's assigned to someone in this group? How long it's with the group in general?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 11:37 PM
Hello @Kieran Anson ,
I want to calculate how long it is assigned to a person of that group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-03-2025 12:51 PM
Try:
if (current.assignment_group.toString() == 'PREP group Sys_id')
convert the Reference value to a string before the compare. I am assuming you are using a sys_id value and not 'PREP group Sys_id'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-04-2025 12:13 AM - edited ‎03-04-2025 12:34 AM