The CreatorCon Call for Content is officially open! Get started here.

Need help to create metric using the Updated by field.

mark141230
Tera Expert

Hi everyone,

I am having problems activating a metric that i can use for my report.

I use the updated by field in the metrics in order for me to get all the people who updated or share inputs for a particular ticket.

Someone discuss this on the other thread and I followed what the instruction but still no luck.

Heres what I did.

1. I created a Business rule in the incident table.

Table: Incident

Run at: Server

Advanced: Check

When to run: After

Insert / Update

Script:

var gru =   new GlideScriptRecordUtil.get(current)

var fieldsChanged = gru.getChangedFieldNames();

gs.eventQueue('metric.update', current, '[sys_updated_by]',1, 'metric_update');

Metrics > Definition

Table: Incident

Field: updated by

Type: Duration

Active

Script: blank

This all i did but didn't work. Hope someone can help me.

Many thank in advance

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

Please post such questions as 'Question' instead of Discussion as more people would take notice of such things...



Change the metric as 'Script Calculation' and paste this in business rules on the change table....



Script:



var metricSysID = 'a106eba143557500eb7948f4b14afc9d'; //replace the sys id of the metric definition



var instanceRecord= new GlideRecord('metric_instance');


instanceRecord.addQuery('id',current.sys_id);


instanceRecord.addQuery('definition',metricSysID);


instanceRecord.addQuery('calculation_complete','false');


instanceRecord.query();



if(!instanceRecord.next()){


      insertMetrics();


}



else


      {


      instanceRecord.end = gs.nowDateTime();


      instanceRecord.duration=gs.dateDiff(instanceRecord.start.getDisplayValue(),instanceRecord.end.getDisplayValue());


      instanceRecord.calculation_complete = true;


      instanceRecord.value = gs.getUser().getFirstName();


      instanceRecord.update();



      if(current.active == true)


              {


              insertMetrics();


      }


     


}



function insertMetrics()


{



      var instanceRecord= new GlideRecord('metric_instance');


      var metricSysID = 'a106eba143557500eb7948f4b14afc9d'; //replace the sys id of the metric definition


      instanceRecord.initialize();


      instanceRecord.definition = metricSysID;


      instanceRecord.start = gs.nowDateTime();


      instanceRecord.id = current.sys_id;


      instanceRecord.value = gs.getUser().getFirstName();


      instanceRecord.calculation_complete = false;


      instanceRecord.insert();


}


Hi Kalaiarasan.



Thank you for the advise and assistance, I have one question though.


You said change the metrics to "script calculation" then add the script in the business rule in the change table?



If I am going to change the metrics to "script calculation" I should put a script on the metrics for it to work. And last why in the change table, should it be in the incident table.



Please enlighten me. many thanks.


Leave the script in metric empty and paste it in a business rule. And yes use incident table. I mentioned change request as a example


That TOTALLY served as an inspiration to solve the issue I was struggling with for the past 3 hours...
THANK YOU SO MUCH!!!