- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 05:56 AM
Hello,
I have a duration field called 'days'. I need to convert the number of days into hours and then set a separate integer field to that number. 1 day should = 8 hours. Example: The user enters 5 days and presses submit, the after insert business rule should set the integer field to 40.
(Please don't throw a bunch of links at me, I have looked everywhere)
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 06:26 AM
you mentioned days in duration type field ?
try now, tested with below code .
var gr = new GlideRecord('incident');
gr.get('f144d5002f849090f68d5ff62799b688');
var ab = gr.u_duration.getDisplayValue();
var op = ab.split(' ')[0];
var hr = parseInt(op*8);
gs.print(hr);
Edit:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 06:30 AM
That is getting me a NaN result:
var ab = current.days.getDisplayValue();
var hr = parseInt(ab * 8);
gs.addInfoMessage(hr);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 06:04 AM
Hi
Try below code.
var hoursCalc = duration/(60*60*1000);
var businessDays = Math.floor(hoursCalc / 24);
var hoursDiff = duration - businessDays*60*60*24*1000;
var durCalc = businessDays*(60*60*12*1000)+hoursDiff;
var durToAdd = new GlideDuration(durCalc);
Make it correct or mark it as helpful, if my response helps you.
Thanks
Bhagyashri Sorte
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 06:06 AM
Make a before insert BR
current.hours_field = parseInt(current.days_field*8);
Please mark my response as correct and helpful if it helped solved your question.
-Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 06:11 AM
That's not working, I'm not sure that you can multiply the entire duration field by 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-03-2020 06:16 AM
I set the duration field to 10 days
Tried this to test your code:
var test = parseInt(current.days);
gs.addInfoMessage(test);
Got this result:
1970.0