Creation of Metric with Script Calculation ?

Mathews1
Tera Contributor

Hi Guys,

 

I would like to create a Metric to capture the "Assigned To" field changes. My requirement is to capture the field changes only for a specific group. When the "Assigned To" of an incident changes for the particular group, then it should be captured in the Metric table.

 

Script which I have used:

 

if (current.incident.assignment_group == "Hardware")
  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, gr.end);
gr.calculation_complete = true;
  gr.insert();

}

 

But the Metric definition is not having / capturing any field change values. Please guide me on thi.

 

Thanks

19 REPLIES 19


Hi Chris,



When I try to save the script specified script, I get error message as "JavaScript parse error at line (4) column (7) problem = invalid return"



if (current.assignment_group.getDisplayValue() != 'Hardware') {


  mi.endDuration();


  return false;


}



Please advise me on this



Thanks


Ah sorry.. It's not a return



if (current.assignment_group.getDisplayValue() != 'Hardware') {


  mi.endDuration();


  answer = false;


}


Thanks Chris..



Code works fine but this particular code doesnt calculate metrics when the Assigned To is empty .. Metric Instance are created only if there is a data (name) in Assigned To at the time of creating an incident, if Assigned To is empty it doesnt create an Metric record.



can you suggets me on this



Thanks


It should as long as the Assignment Group is hardware.   Are you needing to capture this initial time (from incident creation to initial assigned to), no matter what assignment group is selected?



If so.. try this (untested)


if (current.assignment_group.getDisplayValue() != 'Hardware' && current.sys_mod_count != 0)


No Chris, this piece of code doesnt capture empty Assigned To.



My requirement is to capture "Assigned To" for Assignment group = Hardware. I want a metric to be created for each Incident related to Hardware whenever there is a change in Assigned To, But the piece of code doesnt create a metric when the Assigned To is empty at the time of creating the incident.



Thanks