Kieran Anson
Kilo Patron

Metric's don't have access to the previous value, only the changed value. I would change your logic to create the metric instance when the state is awaiting acceptance, and close it when in WIP.

 

//answer and mi are passed in as part of MetricInstance script include
//calling eval()
(function(definition, current , answer, mi) {

	//using type 'Field value duration' to cater for
	//scenarios where state could cycle, and we want to create 
	//a new metric instance each time

	//Cancel existing metrics and create a new one
	if(current.getValue(definitionField) == sn_hr_core.hr.STATE_AWAITING_ACCEPTANCE){
		answer = true; //will end any previous metric instances, and create a new one
		return;
	}

	if(current.getValue(definitionField) == sn_hr_core.hr.STATE_WORK_IN_PROGRESS){
		mi.endDuration();
		answer = false; //will end any previous metric instances, and not create a new one
		return;
	}

	
})(definition, current, answer, mi);

 

KieranAnson_0-1740143502255.png