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.

Create Metrics Definition to capture Updated By

wesley_p
Kilo Contributor

Hey everyone, 

I'm a novice with ServiceNow (currently Jakarta), and our organization doesn't have a developer, so if I want something, I have to learn it myself.  I'm normally fine with that, but I'm stuck on a recent project. 

I need to report on the # of Work Notes updates made, grouped by user.  By my research, I'll need to script a Metrics Definition to collect this information.  I'm trying to do this, but I'm not having any luck.  

For some context, I want to report on Work Notes updates by user because I have a team of student workers who can't take ownership for Incidents per ITIL's normal methodology.  If I have a number of Work Notes updates per Student Tech, I can use that to gauge how many tickets/week are being worked on.  

Here's what I have so far: 

find_real_file.png

// variables available
// current: GlideRecord - target incident
//definition: GlideRecord - (thisrow)

if (current.work_notes.changes())
	createMetric();

function createMetric(value) {
  var mi = new MetricInstance(definition, current);
  if (mi.metricExists()) 
    return;
	
	var gr = mi.getNewRecord();
	gr.start = current.sys_created_on;
	gr.end = current.sys_updated_on;
	gr.value = current.sys_updated_by.getDisplayValue();
	gr.insert();
}

Any suggestions?  Thank you!

1 ACCEPTED SOLUTION

Michael Fry1
Kilo Patron

You can't use .changes() in a metric script. It only accept current, period. You can throw that script into a business rule.

Review this thread on how to do that: https://community.servicenow.com/message/899065#899065

View solution in original post

3 REPLIES 3

Michael Fry1
Kilo Patron

You can't use .changes() in a metric script. It only accept current, period. You can throw that script into a business rule.

Review this thread on how to do that: https://community.servicenow.com/message/899065#899065

Thank you Michael!  I followed the instructions in that thread and am now able to report on changes in the Incidents table.  

Great!