I need a scripted breakdown that will dot-walk from metric_instance to the ID field to fields that are on that document ID

George P
Tera Guru

I am attempting to create a breakdown that looks at certain records on the metric_instance table and breaks down on the ID.User field.  Can someone provide some guidance on how I would make a script dot-walk through a document ID field?

1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee
ServiceNow Employee

Don't use a script for this.  You'll get much better performance if you create a view to the table you are looking for (e.g., incident, case, etc.) and then build your indicator on that.  There was a lab on this at K19 which walks you though using Performance Analytics on metrics. (I believe it is this one: https://community.servicenow.com/community?id=community_article&sys_id=686623dcdb9d3b0422e0fb2439961...)

View solution in original post

5 REPLIES 5

ServiceNowSteve
Giga Guru

Well the ID field is just a reference to the incident. I am not sure where you want to run this script so some variables might change but for the sake of this let's pretend you're running a fix script.

You could do something like this.

var metric = new GlideRecord('metric_instance');
metric.addQuery('id', 'SYS_ID OF THE INCIDENT');
metric.query();

if(metric.next())
  {
   var name = metric.getValue('id.name');
  }

or if that dot walk doesn't work you can go the long way around

var metric = new GlideRecord('metric_instance');
metric.addQuery('id', 'SYS_ID OF THE INCIDENT RECORD');
metric.query();

if(metric.next())
  {
   //Get the sys_id from the ID field
   var incId = metric.getValue('id');

   //Now query the incident table with that id
   var inc = new GlideRecord('incident');
   inc.addQuery('sys_id', incId);
   inc.query();

   if(inc.next)
     {
      var name = inc.getValue('name');
     }
  }

You don't want to use a script for this in PA, but if you were using one, I think you would want to pull the table from the dot walking to the metric definitions and looking at what table the definition is on (if it was incident, you would just use the OOTB incident_metric view).

Adam Stout
ServiceNow Employee
ServiceNow Employee

Don't use a script for this.  You'll get much better performance if you create a view to the table you are looking for (e.g., incident, case, etc.) and then build your indicator on that.  There was a lab on this at K19 which walks you though using Performance Analytics on metrics. (I believe it is this one: https://community.servicenow.com/community?id=community_article&sys_id=686623dcdb9d3b0422e0fb2439961...)

It took some time to get our developers to build the database view, but once I had access to it, it worked perfectly.  Thanks