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.

Capture hr service, transffered to, transffered from in Metric defination

Prateek07
Tera Contributor

Hi All,

I have a requirement for HR case transfer, where i wanted to see how much time a HR case has spent in one HR service.

I have created 3 metric definitions one for Field = HR service, Transferred to and transferred from. Attaching the screenshot for reference.

Problem - I am not getting any input in metric definition, i created a new case after creating the metric definition and transferred multiple cases, multiple time. Ran lot of testing too. 

Please suggest how can i achieve that?

Prateek07_0-1698046724318.png

Prateek07_1-1698046908246.png

Prateek07_2-1698046923623.png

 

Thanks in Advance

 

9 REPLIES 9

Danish Bhairag2
Tera Sage

Hi @Prateek07 ,

 

hope u have created a Business rule on those tables as well which will help create a metric instance?

 

Thanks,

Danish

 

@Danish Bhairag2 but we dont create Business rule when we create metric definition state or assignment group. Is it mandatory to have a BR to trigger a metric defination?

Hi @Prateek07 ,

 

Please check this article

https://www.servicenow.com/community/platform-analytics-forum/metric-definition-not-firing-on-alm-ha...

 

Also I have provided u the business rule in this post itself.

 

Thanks,

Danish

 

@Prateek07 

 

Business Rule

When: after

Insert: true

Update: true

delete: true

 

queueMetricUpdate();

function queueMetricUpdate() {    
	var gru =  new GlideScriptRecordUtil.get(current);
	var fieldsChanged = gru.getChangedFieldNames();
	var gr = getDefinitions(fieldsChanged);
	fields = '';
	while (gr.next())
		fields += gr.field + ',';
	
	if (fields.length > 0) {
		fields = '[' + fields.substring(0, fields.length - 1) + ']';
		gs.eventQueue('metric.update', current, fields, current.sys_mod_count, 'metric_update');
	}
}

function getDefinitions(fields) {
	var gr = new GlideAggregate('metric_definition');
	gr.addActiveQuery();
	var tables = GlideDBObjectManager.getTables(current.getTableName());
	gr.addQuery('table', tables);
	gr.addQuery('field', fields);
	gr.groupBy('field');
	gr.query();
	return gr;
}

 

Thanks,

Danish