Creation of Metric with Script Calculation ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-04-2014 06:45 AM
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
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2014 08:20 AM
I think the issue might be that the assigned_to field is not actually changing. The easiest way to correct for this is to trigger a metric event in a new business rule, with the 'assigned_to' field as being changed. You'll have to have some conditions on group field, looking at previous and current assigned_to, and trigger an event sending assigned_to as the changed field(look at the current metric events business rule for the format). Unfortunately I'm omw out of town, but hopefully this points you in the right direction.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-17-2014 11:16 AM
An on insert business rule on the incident table with the condition current.assigned_to.isNil()
gs.eventQueue('metric.update', current, '[assigned_to]', current.sys_mod_count, 'metric_update');
The reason a record wasn't getting created is that the assigned_to field wasn't a field that changed. The above code will tell the metric events processor to start a metric for assigned_to with the blank value.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2014 09:07 AM
Hi Mathews,
use the condition 'current.assinged_to.changes();' so that it will take care of your empty "assigned to" field as well.
Hope this should work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2017 03:04 AM
Hi
i have the same issue. Metric instance value is starting from zero. I want it to be starts from 1.
please suggest.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-20-2020 09:50 PM
Can someone answer this metric related question . Please
https://community.servicenow.com/community?id=community_question&sys_id=92bd9c38db5b18903daa1ea66896191d