Metric_instance records are being duplicated
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2017 10:19 AM
I created a metric (code below) which is using:
Table:Incident
Field: Work notes
Type:Script calculation
The goal is to create a metric instance when a User adds a work note. But I am seeing duplicate metric records (different sys_id but same field values) . It also appears that this only happens when you hit Post instead of hitting Saving/Updating. I have also seen this behavior when I attempt to add a Work note to an Incident.list instead of actually being in the Incident form
// variables available
// current: GlideRecord - target incident
// definition: GlideRecord - (this row)
createMetric();
function createMetric() {
// Only process for IT Service Desk TMSS Team
if (current.assignment_group.getDisplayValue()!='IT Service Desk TMSS' )
return;
var mi = new MetricInstance(definition, current);
var gr = mi.getNewRecord();
var uname = current.sys_updated_by;
var ugr = new GlideRecord('sys_user');
ugr.get('user_name', uname);
/*Note: You can only update 'value' field if you don't update 'field_value'. There is a OOB Business rule on Metric Instance which will override 'value' field before insert, if you change 'field_value'.*/
gr.value = ugr.sys_id;
gr.field = definition.field;
gr.start = current.sys_updated_on;
gr.end = current.sys_updated_on;
gr.calculation_complete = true;
gr.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2017 03:48 PM
no worries, hope you get to the bottom of it!