- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2023 01:26 PM
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:
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 06:40 AM
@Digit Tried and tested solution. Update the last line of code as below
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 07:56 AM
@Digit Have you tried this? This should definitely work. Please try and mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2023 01:33 PM
You need to look at the max_unit attribute for the duration field. That will tell the system to display the field in total days, hours or minutes.
I believe these are all of the valid values
max_unit
Sets the maximum unit of time for the duration. Possible values are max_unit=days,max_unit=hours,max_unit=minutes, and max_unit=seconds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 06:26 AM
Thanks for the suggestion, Drew!
The problem is that I don't want to limit the duration to minutes. If the time_in_open field = 90 minutes for example; I would want the open_total to display as 1 hour 30 minutes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 06:40 AM
@Digit Tried and tested solution. Update the last line of code as below
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 07:56 AM
@Digit Have you tried this? This should definitely work. Please try and mark as correct answer if this solves your issue.
ServiceNow Community Rising Star, Class of 2023