How can we report on tickets 'touched' or 'handled' by an Assignment Group using Metric Definition?

Piyali1
Giga Contributor

I have used below script: This is also taken from community, somehow this is not working for me: 

Can someone assist me?

(function calculateMetric(current, definition, mi) {


// Check to see if a metric instance already exists for this ticket


// assigned to this assignment group


var grMetric = new GlideRecord('metric_instance');


grMetric.addQuery('id', current.getValue('sys_id'));


grMetric.addQuery('definition', definition.getValue('sys_id'));


grMetric.addQuery('value', current.getDisplayValue('assignment_group'));


grMetric.query();


if (grMetric.hasNext()) {


// If so, then this ticket has already been counted for this assignment


// group and there's no need to do anything.


} else {


// If not, create one


var now = new GlideDateTime();


var instant = new GlideDuration(0);

 

 

grMetric = new GlideRecord('metric_instance');


grMetric.initialize();


grMetric.setValue('table', current.getRecordClassName());


grMetric.setValue('id', current.getValue('sys_id'));


grMetric.setValue('definition', definition.getValue('sys_id'));


grMetric.setValue('field', definition.getValue('field'));


grMetric.setValue('value', current.getDisplayValue('assignment_group'));


grMetric.setValue('duration', instant);


grMetric.setValue('business_duration', instant);


grMetric.setValue('calculation_complete', true);


grMetric.setValue('start', now);


grMetric.setValue('end', now);


grMetric.insert();


}


})(current, definition, mi);

1 REPLY 1

Kieran Anson
Kilo Patron

Hi,

If you just want "touch" i.e even if the ticket is passed back, you'll only have one record, the below script will fulfil this requirement.

Type = Script Calculation

var mi = new MetricInstance(definition, current);

if(!metricExists()){
	var gr = mi.getNewRecord();
	gr.value = current.getDisplayValue('assignment_group');
	gr.calculation_complete = true;
	gr.insert();
}


function metricExists() {
	var gr = new GlideRecord('metric_instance');
	gr.addQuery("id", current.sys_id);
	gr.addQuery("definition", definition.sys_id);
	gr.addQuery('value',current.getDisplayValue('assignment_group'));
	gr.query();
	return gr.hasNext();
}