Duration field 1 day = 8 hours

march
Kilo Guru

Hi Community

 

We got the requirement from our Development Team to have new duration field added.

Until there no Problem.

 

The point is that they want 1 day = 8 hours

ie: when a user enter 10 hours, SNOW display that as 1 day and 2 hours.

But also that when we for example do an excel report the exported value of a record with a duration of 1 day and 2 hours is not (24+2)*60*60=93600, but (8+2)*60*60=36000


Is there an existing attribute allowing to control this? Or do we have to play with the stored value using Business Rules?


Thanks

Marc.

11 REPLIES 11

Hi Robin,



This is what we have done for now as well.


To be honest, i was also expecting a more elegant solution to be available for this.


na93
Mega Expert

Hi March,



Did you get any luck with this? We have a similar requirement where we would like if 7.5 hours is entered for this to tally to 1 day.



Regards,
Nabeel


Feiry
Tera Contributor

Hello Nabil,

Did you resolve this issue?

I'm facing the same problem.

 

Thanks in advance

andrewpilachows
Kilo Guru

The duration field just stores an integer value (milliseconds) that it displays in a d/h/m/s format based on a 24 hour clock.   You might be able to use something like DurationCalculator or a Schedule Duration where you accept the number of hours input into a text field, then calculate the duration based on business hours and then store the duration in the field to display to the user.   But this would still be just the number of milliseconds based on a 24 hour clock.   You would then either have to reverse engineer this for reporting, or have a secondary field in which you store the actual non-business duration which you would use for reporting.   So one field would have the 10 hours duration, and the other field would have the 1 day 2 hour duration (could even be a text or numeric field too).


Using DurationCalculator To Calculate a Due Date - ServiceNow Wiki


randrews
Tera Guru

in the below script include change the dayLength variable to 8... call the script include with the duration value and it will return a new value that will make it display in a user friendly manner.



Also are you sure they want 8 hour days?? most workplaces don't think about it but they use a 9 hour day... 8-5 with an hour for lunch.. this is actually a 9 hour work day.




function FAsetDisplayDuration(input_dur){


        var tag = false;


        var add_day = 0;


        var new_day = 0;


        var new_hour = 0;


        var new_minute = 0;


        var dayLength = 9;   //how many hours in a business day


        var oneDay = (1 * dayLength * 60 * 60) * 1000;


        var oneHour = (60*60) * 1000;


        var oneMinute = 60*1000;


        var value_calc = 0;


        var timems = input_dur.getNumericValue();


        //calculate what business duration should be set based on the value of the duration field.


      if(timems > oneDay){


                value_calc = timems/oneDay;


              //gs.addInfoMessage('raw new day is ' + value_calc);


                new_day = parseInt(value_calc);


                //take the days out of the calculated value so we can get the hours


                value_calc = (value_calc - new_day);


                //calculate the new hours;


                value_calc = value_calc * 9;


      }


      else{if(timems > oneHour){


                value_calc = timems/oneHour;


              }


                else{


                  new_minute = timems/oneMinute;


                  tag = true;


                }


              }


      if(!tag){


              new_hour = parseInt(value_calc);


              //take the hours of of the value so we can calculate minutes


              value_calc = (value_calc - new_hour);


              add_day = parseInt(new_hour/9);


              new_hour = new_hour - (add_day * 9);


              new_day = new_day + add_day;


              value_calc = value_calc * 60;


              new_minute = parseInt(value_calc);


              }


      //convert the new values to a new value we can set


      //gs.addInfoMessage('calculating new value new day is' + new_day + ' new hour is ' + new_hour + ' new minute is ' + new_minute);


      value_calc = ((new_day * (24*60*60*1000)) + (new_hour * (60*60*1000)) + (new_minute * (60*1000)));


              var final_dur = input_dur;


      final_dur.setNumericValue(value_calc);


            return final_dur;


}