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 ,

 

Please create a business rule on your HR case table which should be a "After" Insert,Update & Delete

 

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;
}

 

Please create this n test it should work.

 

Thanks,

Danish

 

@Danish Bhairag2  do i need to create the BR in global or in Human Resources: Core application? 

@Prateek07 ,

 

You can create it in the same scope in which the HR case table is.

 

Thanks,

Danish

 

@Danish Bhairag2 

I am getting an error after submitting the case and it is not captured in metric definitions.

"GlideScriptRecordUtil is not allowed in scoped applications"

 

do i need to mention the field names in script or it can be blank as well?

	var gr = getDefinitions(fieldsChanged);
	fields = '';

 

Prateek07_0-1698049292863.png

 

@Prateek07 ,

 

M so sorry I have created this in Global so never faced this. Could u please create it in a global scope n check. Apologies for the rework.

 

In script u don't need to add or modify anything

 

Thanks,

Danish