Convert duration field to hours where 1 day = 8 hours

JJG
Kilo Guru

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)

1 ACCEPTED SOLUTION

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:

 

View solution in original post

9 REPLIES 9

Harsh Vardhan
Giga Patron

sample code:

 

 

var ab = current.number_of_days;

var hr = parseInt(ab*8);

current.<fieldName> = hr;

That's not working, I'm not sure that you can multiply the entire duration field by 8

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

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: