Script for minutes in each month

robertmueller
Giga Contributor

Hello

 

Is it possible to have a formula that will auto calculate the minutes in each month. I have a formila indicator which needs to be:

Minutes per month - Outage down time

I have an indicator to calculate the outage down time per month but how can you script it to confirm the minutes per month. ie

June would be "43200 - Outage down time", but July would be "44640 - Outage down time" as June has 30 days and July has 31.

1 ACCEPTED SOLUTION

Adam Stout
ServiceNow Employee
ServiceNow Employee

Try using a formula for this:

{{Number of open incidents}}
score_end.getDaysInMonth() * 1440

View solution in original post

6 REPLIES 6

Dubz
Mega Sage

you can use the glide date time method getDaysInMonth()

 

var gdt = new GlideDateTime(); //December
gs.print(gdt.getDaysInMonth());

 

https://developer.servicenow.com/app.do#!/api_doc?v=kingston&id=r_GDT-getDaysInMonth

Will this work? ie being in December would it show Novembers figures as 30 days still?

I'm no expert with GlideDateTime so you might have to do some testing but you should be able to set the value of the gdt eg:

var dateTime = '2018-11-31 08:00:00';
var gdt = new GlideDateTime(dateTime);
gs.print(gdt.getDaysInMonth());

robertmueller
Giga Contributor

The script I have at the moment is:

 

if ([[Indicator / By month SUM +]] > 0) {43920/[[Indicator / By month SUM +]]} else { 43920 }

 

Where "Indicator" is the name of the indicator I am getting the records from.