Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

To create metric definition on field type "updated By"

eumak
Tera Guru

I am working on making a metric defination on field type "updated By" . According to below article it says "sys_updated_by aren’t monitored for metric calculations"  I created a BR as the steps but still at zero.

https://tilnow.co/metrics/2015/05/30/metric-for-updated-by/

Can someone guide me on how i can get the metric instance records created for my definitions for updated_by field? If someone has implemented it would love to see script of BR / & definition.

Thanks
Tushar

Mark it as helpful or correct, If Applicable


Cheers..!

Happy Learning:)

Tushar
1 REPLY 1

Manmohan K
Tera Sage

Hi @eumak ,

 

You can create a metric definition like below

ManmohanK_0-1683840105736.png

 

createMetric(current.sys_updated_by.toString());

function createMetric(value) {
	var mi = new MetricInstance(definition, current);
	var gr = mi.getNewRecord();
	gr.field_value = value;
	gr.calculation_complete = true;
	gr.insert();
}

 

 

Then you can a Business rule like below 

ManmohanK_1-1683840211390.png

 

Add below code in advanced tab of BR

 

(function executeRule(current, previous /*null when async*/) {

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

})(current, previous);

 

 

This should get metric instances created for sys_updated_by field. I got the below results

 

ManmohanK_2-1683840398561.png

 

Please mark answer as helpful and correct if it resolves the issue

Thanks !!!