- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 09:29 AM
Hi All,
I have a requirement to convert the business duration value into hours.
right now value is populating as days hours minutes
I tried some scripts but that is not working.
Please help in this.
Thanks,
Sam
Solved! Go to Solution.
- Labels:
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 11:27 AM
From days hours minutes seconds to hours minutes seconds would look like this
var hrs = parseInt(current.u_dura.dateNumericValue()/(60*60*1000));
var mins = parseInt(parseInt(current.u_dura.dateNumericValue()-(hrs*60*60*1000))/(60*1000));
var secs = parseInt(current.u_dura.dateNumericValue()-(hrs*60*60*1000)-(mins*60*1000))/1000;
gs.addInfoMessage(hrs + ' hours ' + mins + ' minutes ' + secs + ' seconds');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 09:56 AM
Hi Sam,
In a Business Rule script you could use
current.business_duration.dateNumericValue()/(60*60*1000)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 10:16 AM - edited 03-12-2024 10:25 AM
Hi @Brad Bowman ,
I added the above script. And it is coming like 1293.0266049382717
I showed to the client. It should be like 212 hours 33 second.
Can we do like this.
Thanks,
Sam
Thanks,
Sam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 11:27 AM
From days hours minutes seconds to hours minutes seconds would look like this
var hrs = parseInt(current.u_dura.dateNumericValue()/(60*60*1000));
var mins = parseInt(parseInt(current.u_dura.dateNumericValue()-(hrs*60*60*1000))/(60*1000));
var secs = parseInt(current.u_dura.dateNumericValue()-(hrs*60*60*1000)-(mins*60*1000))/1000;
gs.addInfoMessage(hrs + ' hours ' + mins + ' minutes ' + secs + ' seconds');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2024 01:14 PM
Hi @Samiksha2 ,
To get duration in hours,
- getByFormat('yyyy-MM-dd hh:mm:ss')
- "new GlideDateTime()" to convert result to GlideDateTime()
- use "getNumericValue()" to get time in milliseconds
var dur2 = duration.getByFormat('yyyy-MM-dd hh:mm:ss'); // convert format var gdt = new GlideDateTime(dur2); // convert to GlideDateTime var hours = (gdt.getNumericValue()/1000)/(60*60); // convert to hours gs.info(hours);
If the question is about time between end_time and start_time, those are GlideDateTime fields. So, it's only necessary to use .getNumericValue() and substract them to get the time in milliseconds. Milliseconds can then be converted to hours.
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda