- 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-10-2023 10:06 AM
Thanks so much, @jaheerhattiwale !!
I was attempting something similar, but you beat me to it. That works perfectly.
Really appreciate the assistance!