How to calculate number of minutes of a month

veronica_malmo
Kilo Expert

Hi,

I would like an indicator that shows how many business minutes there is in a month. I have a schedule and by using that I want it to calculate the minutes so I can show it in an indicator. 

I have one indicator that calculates the minutes an incident has been open (business hours) but I need another indicator to divide it by the total business minutes in the month. Can I do this directly in an indicator, or do I need to create a table to hold the data?

6 REPLIES 6

Jane Stone
Kilo Guru

I had this exact same challenge! Here's how I did it.

First, create a Calendar entry using the Calendars app. I called mine Availability. Add 1 entry (I set the day of week as Monday). In my case I just wanted to count all the minutes in every day so my start time was 00:00:00 and End Time 23:59:59. Now that you have a calendar entry, you just create an indicator to collect the data. Indicator Source uses Table sys_cal_day and you specify your calendar. In my simple case where it's the same every day, I don't need any other conditions. In the automated Indicator, I have a SUM on a script which is simply:

var diff=function(x,y){return y.dateNumericValue() - x.dateNumericValue();};
var minutes=function(x,y){return diff(x,y)/(60*1000);};

minutes(current.start_time1, current.end_time1);

And that's all there is to it!  You now have your 'Available Minutes' captured each day and can use this in any calculations you need.

Hi @Jane Stone ,

 

Can you please help with some questions around using sys_cal_day table

1. Are there any impacts of creating new records on sys_cal_day table?

2. Are there any impacts on schedules of servicenow instance SLA's or any other calendar fields?

I have not seen any adverse impacts of having created the calendar entry. It has definitely not impacted SLAs.

veronica_malmo
Kilo Expert

Wow, thanks! Didn't know there was a calendar app, just the schedule. Now I have to figure out how to use different days so it won't count holidays and weekends.. Guessing I must use the Day of week field in the script somehow. Getting closer but not quit there yet, thanks for the push in the right direction 🙂