How to display minutes in a duration field

Digit
Kilo Guru

I have a business rule that calculates the time (in minutes) a record has been in Open state. Everything is working wonderfully, except that I am now trying to display the minutes value on the form in a duration field, which is taking the minutes value and storing it as hours instead.

Example:

My u_time_in_open field = 6 (6 minutes)

I want my u_open_total field to also equal 6 minutes, but as written, it displays as 6 hours:

Digit_0-1673299449893.png

I'm sure it's a simple thing I'm missing, but I can't think of it.

Any suggestions?

 

Here's my code:

var initTime = current.u_time_in_open; //Initial value (in minutes)

    var startDate = new GlideDateTime(current.u_open_state);
    var endDate = new GlideDateTime();
    var schedule = new GlideSchedule('563653c8db670bc09b71753a8c96194d', 'UTC'); 
    current.u_open_duration = schedule.duration(startDate, endDate);

    //update the aggregated duration and convert from milliseconds to minutes
    current.u_time_in_open = (current.u_open_duration.dateNumericValue() / (60 * 1000)) + initTime; 
    current.u_open_total = new GlideDuration(current.u_time_in_open); //duration

 

2 ACCEPTED SOLUTIONS

jaheerhattiwale
Mega Sage
Mega Sage

@Digit Tried and tested solution. Update the last line of code as below

 

current.u_open_total = "00:"+current.u_time_in_open+":00";
 
 
Please mark as correct answer if this solves your issue.
Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

@Digit Have you tried this? This should definitely work. Please try and mark as correct answer if this solves your issue.

Please mark the answer as correct or helpful based on impact
ServiceNow Community Rising Star, Class of 2023

View solution in original post

5 REPLIES 5

Digit
Kilo Guru

Thanks so much, @jaheerhattiwale !! 

I was attempting something similar, but you beat me to it. That works perfectly.

Really appreciate the assistance!