graycarper
Giga Guru

As of this writing, with or without Performance Analytics enabled, ServiceNow doesn't come preconfigured to measure Incident First Reply Time (the amount of time it takes an agent to write the first public comment). Prior to migrating to ServiceNow, we had been using First Reply Time for years, in coordination with other KPIs (like update frequency, resolution time, and rework), to continuously improve our customer satisfaction. It was one of the first metrics we wanted to recreate once we were up and running. This article describes our process.

We approach First Reply Time from two angles, table metrics and platform metrics, to give greater flexibility in reporting. You can feel free to simplify it by removing one or the other. If you aren't sure how, just leave a comment below and @-mention me in it.

First, we first add five new fields to the Incident table, each named with an "u_mm_" prefix to indicate this was created by Michigan Medicine. One field records the exact time of first reply, the others record different formats for the duration between the time the Incident was opened and the time the first reply was posted. (We record both the business and calendar durations in hours:minutes:seconds format and a sum of seconds format, the same way that resolution time is recorded in the Incident table.) Once the fields are created, we add a new Metric definition, then a new Business Rule to watch for the first reply event. When the first reply happens, the Business Rule sets all the new field values and inserts a new metric into the metric_instance table. We then remove all the new fields from the Incident form (so they don't clutter the interface).

Step
Action
1Login to ServiceNow as a user with the admin role.
2Click Tables under System Definition in the left-navigation bar. Search for the Incident table and open it, then click New beside Table Columns. Set Type to Date/Time, Column Label to First Reply At, and Column Name to u_mm_first_reply_at. Click Submit.
3Create another new Incident table column. Set Type to Duration, Column Label to First Reply Business Duration, and Column Name to u_mm_first_reply_business_duration. Click Submit.
4Create another new Incident table column. Set Type to Duration, Column Label to First Reply Duration, and Column Name to u_mm_first_reply_calendar_duration. Click Submit.
5Create another new Incident table column. Set Type to Integer, Column Label to First Reply Business Seconds, and Column Name to u_mm_first_reply_business_stc. Click Submit.
6Create another new Incident table column. Set Type to Integer, Column Label to First Reply Seconds, and Column Name to u_mm_first_reply_calendar_stc. Click Submit.
7Click Definitions under Metrics in the left-navigation bar and then click New beside Metric Definitions. Set Name to Incident First Reply Time, Table to Incident [incident], Field to First Reply At, Type to Script Calculation, and Description to If this is the first public reply to the Incident by an Agent with the itil role, create a metric instance and record the first reply duration. This script is empty because a business rule does the heavy lifting. Click Submit.
8Click Definitions under Metrics in the left-navigation bar and then open the metric you just created. Look in your browser's URL field and you will see sys_id followed by a string of numbers and letters (like "462cf6520a25810200ebe763047cc273") in between '=' (or %3D) and '&' (or %26). Copy that string. It's the sys_id for your new metric and you'll need that in the next step.
9

Click Business Rules under System Definition in the left-navigation bar. Click New beside Business Rules. Set Name to Set Incident First Reply Time, Table to Incident [incident], and Advanced to true. On the When to Run tab, set Update to true and add two filter conditions that both must be met: First Reply At is empty AND Additional Comments changes. Click the pencil icon to edit user roles, add the itil role, and click Done. On the Advanced tab, set Script to:

// Set metricSysID to the sys_id of the Incident First Reply Time metric definition.

var metricSysID = '4322bf44db730300f653f34ebf96193e';

// Set scheduleSysID to the business hours schedule you want (System Scheduler > Schedules > Schedules). "8-5 weekdays excluding holidays" is default.

var scheduleSysID = '090eecae0a0a0b260077e1dfa71da828';

// If this is the first public reply from an itil-role agent, u_mm_first_reply_at isn't set

if (current.u_mm_first_reply_at.nil())

  // Set u_mm_first_reply_at to the current time

  current.u_mm_first_reply_at = gs.nowDateTime();

// Update the fields that indicate the time/duration of the incident from open to first reply.

// Keep track of duration as a glide_duration value (dd hh:mm:ss) and as a pure number of seconds.

// Both calendar time and business time are maintained.

var dataChange = current.opened_at.changes() || current.u_mm_first_reply_at.changes();

var schedule = new GlideSchedule();

schedule.load(scheduleSysID);

if (dataChange || current.u_mm_first_reply_business_duration.nil())

  current.u_mm_first_reply_business_duration = schedule.duration(current.opened_at.getGlideObject(), current.u_mm_first_reply_at.getGlideObject());

if (dataChange || current.u_mm_first_reply_business_stc.nil())

  current.u_mm_first_reply_business_stc = current.u_mm_first_reply_business_duration.dateNumericValue()/1000;

       

if (dataChange || current.u_mm_first_reply_calendar_duration.nil())

  current.u_mm_first_reply_calendar_duration = GlideDateTime.subtract(current.opened_at.getGlideObject(), current.u_mm_first_reply_at.getGlideObject());

if (dataChange || current.u_mm_first_reply_calendar_stc.nil())

  current.u_mm_first_reply_calendar_stc = current.u_mm_first_reply_calendar_duration.dateNumericValue()/1000;

// Look for this metric_instance record

var instanceRecord = new GlideRecord('metric_instance');

instanceRecord.addQuery('id',current.sys_id);

instanceRecord.addQuery('definition',metricSysID);

instanceRecord.addQuery('calculation_complete','false');

instanceRecord.query();

// If a metric_instance record doesn't already exist

if(!instanceRecord.next()) {

      // Create a new metric_instance record

      insertMetric(metricSysID);

}

function insertMetric(metricId) {

  var instanceRecord = new GlideRecord('metric_instance');

  instanceRecord.initialize();

  instanceRecord.definition = metricId;

  instanceRecord.start = current.sys_created_on;

  instanceRecord.end = current.u_mm_first_reply_at;

  instanceRecord.duration = GlideDateTime.subtract(instanceRecord.start.getGlideObject(), instanceRecord.end.getGlideObject());

  instanceRecord.calculation_complete = true;

  instanceRecord.id = current.sys_id;

  instanceRecord.value = instanceRecord.duration.dateNumericValue()/1000;

  instanceRecord.insert();

}

Click Submit.

10
Click All under Incident in the left-navigation bar. Open any incident you like. Click the hamburger icon to expand the Additional Actions menu, then click Form Layout inside the Configure submenu. In the Selected list, shift-select First Reply At, First Reply Business Duration, First Reply Duration, First Reply Business Seconds, and First Reply Seconds. Click the < button to move them to the Available list, then click Save.
Comments
Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

Thanks for sharing Gray!


Any reason you choose custom fields over platform metrics?


graycarper
Giga Guru

Hi, arnoud! So sorry for my slow reply - I didn't see this comment until now and for some reason the system didn't email me about it. (I'd better check my notification settings!)



When I first started exploring ways I might create First Reply Time, I ran across a support forum discussion that described a solution involving platform metrics. I originally intended to follow that solution verbatim, but as I began implementing it, I realized two things...


  1. It involved creating new custom fields and metrics. I thought it would be simpler, and easier for others to follow, if I could do it with just one.
  2. The incident table includes all the resolution time measurements (business_stc, calendar_stc, business_duration, calendar_duration), so I treated that as a kind of precedent for how to handle Incident event durations.

But! I'm still new to ServiceNow and I'm pretty ignorant about platform metrics. If you think there's a better / cleaner way to do this (e.g. one that only involves metrics and doesn't require new Incident fields), I'd love to learn about it!



-Gray


andreas_holgers
Kilo Expert

Hi, this is exactly what one of our departments are looking for. The problem is that they are in there own application of ServiceNow, not on the Incident table.



So my question is, could I get this to work without involving PA? Maybe just show the Reply time on a table column.



/Andreas (New to ServiceNow)


graycarper
Giga Guru

Hi, andreas.holgersson!



Yes, absolutely, you can start measuring this immediately without PA. I'm really just using PA to calculate hours from seconds, but you could do that in the Business Rule calculation (step 7) instead if you like. All you really need are steps 1-8, and in those steps you'll just need to replace the Incident table with whichever table holds the tasks you want to measure. Once you're done, you can use the Reports module to chart the new data (First Reply Business Duration, First Reply Duration, First Reply Business Seconds, First Reply Seconds) using the table you added it to.



Does that make sense? Please feel free to ask more questions if you have any.



-Gray


andreas_holgers
Kilo Expert

Thank's for your reply and help on my issue. I had to do some small changes though, due to the table was in a scoped application.



But I can't get the First Reply Calender Duration to work. Do you have any ideas? The Business duration works fine.replytime.PNG


/Andreas


graycarper
Giga Guru

Hi!



Hmm. Interesting. Does the 'First Reply Seconds' field have the same problem? It's calculated almost exactly the same way as 'First Reply Duration', so it might give us some clues.



My first guess is that it's a javascript issue, so reply with your Business Rule script so that I can look over that. It could be a problem with the field definition, so also upload a screenshot of your u_mm_first_reply_calendar_duration definition from the table where you put it.



Thanks!


-Gray


andreas_holgers
Kilo Expert

Hi!



I have to admit that I'm a bit ashamed. It was as you thought an issue with the field definitions.


Now it works when I corrected them to so they match.



Again, many thank's   for your time and big help.



/Andreas




 


andreas_holgers
Kilo Expert

Sorry to bother you again, did Another test. The variables show the same amount of time. So I Think I need your help again.



Attaching some screenshots.



/Andreas


time_wrong_calc.PNG


br_time_calc.PNG


time_calendar.PNG


graycarper
Giga Guru

Hi!



I can see why you're getting the same data for each one: You're using the same function for all four calculations (GlideDateTime.subtract) with the same two parameters passed to each (opened and first_replied).



If you look at the original javascript, you'll see that the calculations are done with two different functions (gs.dateDiff and gs.calDateDiff), and those functions take a different final parameter depending on whether it's producing duration or seconds data (true or false).



gs.calDateDiff takes business hours into account, so we'd need to find an equivalent GlideDateTime function for that in order to properly convert the script to GlideDateTime.



What happens if you use the original gs.* calculations? Do you run into problems?



-Gray


andreas_holgers
Kilo Expert

I tried with DateDiff, doesn't get any error message, but there isn't any value in the fields.


With calDateDiff I got error messages that it doesn't work in scoped applications.


time_empty.PNG


new.png


/Andreas


andreas_holgers
Kilo Expert

Hi again,



I looked into the business duration a bit more and found out that it doesn't   show any value on the incident table either.


So maybe this problem is a bit bigger, something that isn't set up correctly.



Incident Table:


duration.PNG


graycarper
Giga Guru

Hi!



Wow - yeah - no business durations in the Incident table definitely makes it seem like there's a deeper problem. That might be something to talk to ServiceNow support about. I also have no experience with writing javascript for scoped applications, so I'm afraid we're beyond my knowledge. My best guess would be that you'd need to find a way for the script to include the gs.dateDiff and gs.calDateDiff definitions, assuming they are both working, but I'm not sure where they are defined. I'm so sorry I'm unable to help more!



-Gray


Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

Again, I would recommend using Metrics.


They also can be used in reports (not only PA)



Using OOB capabilities is recommended, rather than creating custom fields.


graycarper
Giga Guru

Hi, andreas.holgersson!



Little did I know when we had this exchange a month ago that my method for calculating First Reply Time was a ticking time bomb. Once we upgraded to Jakarta, gs.calDateDiff became non-functional, and I began seeing problems similar to you (though I'm not working in a scoped application). Today I rewrote the method we use to create Incident First Reply Time so that it works with Jakarta and, since I moved to GlideDateTime and GlideSchedule, hopefully with scoped applications too. The document here has been updated to reflect this.



-Gray


graycarper
Giga Guru

Hi, arnoud! I finally have platform metrics experience under my belt, so today I updated this document to include a platform metric solution in addition to the table metric solution. The two are integrated here, but anyone who wants to use only one will be able to with a few edits.



-Gray


andreas_holgers
Kilo Expert

Hi graycarper,


Thanks for the input and all the help.


I will look into your updated method, as we are going to upgrade to Jakarta in the Spring, and rewrite mine if necessary.



/Andreas Holgersson


NMcLaren
Tera Contributor

This is working well for us, but we would like to add a trigger that also sets this on first email sent from within the ticket (direct email, not a standard notification). I've tried using various BRs on the Incident and Email tables without luck. Any suggestions?

graycarper
Giga Guru

Hi, @NMcLaren! I'm so sorry for my delayed reply - I'm just returning to work from a long vacation.

 

If I understand you correctly, it sounds like you're saying there's a means to send an email from an Incident without making any changes to the fields of that Incident, and you'd like First Reply to be set when that happens. Is that right? If so, I'm not aware of a way to send an email without making a change to an Incident field, so I'll need more information on how you're doing that.

 

I can at least say that I've never tried to configure a Business Rule to watch for outbound email, so if that ends up being a requirement I don't think I can help. It could be better to pose that question in its own thread or possibly to ServiceNow Support.

 

-Gray

Zaman Sm
Tera Expert

Hey@graycarper ,

will I be able to implement the same in sc_req_item table?

 

what are things do I have to change or keep in mind?

 

Thanks in advance

Version history
Last update:
‎10-19-2017 10:51 PM
Updated by: