Metrics definition for certain group

SM123
Tera Expert

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();
		
    }

 

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

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))

KieranAnson_0-1741085958882.png

 

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

 

 

View solution in original post

18 REPLIES 18

Kieran Anson
Kilo Patron

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?

Hello @Kieran Anson ,

I want to calculate how long it is assigned to a person of that group

Bert_c1
Kilo Patron

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'.

Hi @Bert_c1 ,

Yes i'm replacing with sysid. still it's not working