Metric_instance records are being duplicated

Ryan153
Giga Expert

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();

}

10 REPLIES 10

no worries, hope you get to the bottom of it!