Metrics scripts

Richard Evershe
Tera Contributor

Hi, 

I'm trying to create a metric script calculation, what I want it to do is during a certain period (Saturday 00:00 --> Monday 04:00hrs) identify if any incident records were escalated from Assignment group-X to  Assignment group-Y (starting with characters ABC) and return columns*.

 

From my understanding reporting won't work as soon as an incident record passes out of Assignment group-Y the record won't be retuned in the dataset.

 

BTW: I've created the metric but am struggling on the scripting element.

 

*Columns:
Number
Business Service
Priority
Short Description
Assignment group (source):
Assigned to (source):
Assignment group (destination):
Assigned to (destination):

1 REPLY 1

Rahul M1
Tera Contributor

I think the metric by itself wont be able to create records that meets your requirement. You may want to use combination of Metric + Business rule.

 

Metric: To hold metrics data.

Business Rule: To insert records to above metric (metric_instance table).

 

1. Create a metric for incident table and assignment group field. Add following code to the "Script" section so the metric by itself does not create any metric_instance records.

 

answer = false;

answer;

 

2. Create a business rule on incident table with condition = Assignment group Changes from "X" AND Changes to "Y".

 

3. Add following code to the business role so it inserts metric_instance record 

 

if (isWeekend()) { // define isWeekend() function as per your date requirement

var instanceRecord = new GlideRecord('metric_instance');
instanceRecord.initialize();
instanceRecord.definition = metricSysID;
instanceRecord.start = gs.nowDateTime();
instanceRecord.id = current.sys_id;
instanceRecord.field = "metric_value_json";
instanceRecord.value = getMetricValueInJsonFormat();
instanceRecord.calculation_complete = true;
instanceRecord.insert();
}

function getMetricValueInJsonFormat() {

 

var jsonObj = {
"number": current.go_live_date.toString(),
"assignment_group_source": previous.assignment_group.toString(),
"assignment_group_destination": current.assgnment_group.toString()
};

return JSON.stringify(jsonObj);
}