Using DurationCalculator to calculate a due date
-
- UpdatedFeb 1, 2024
- 6 minutes to read
- Washington DC
- Building applications
Using the DurationCalculator script include, you can calculate a due date, using either a simple duration or a relative duration base on schedules.
The following script demonstrates how to use the global API DurationCalculator to calculate a due date. The first part of the script illustrates how to set a start datetime using the setStartDateTime() method and then use the calcDuration() method to determine a due date that is "x" amount of continuous time (seconds) from the specified start datetime. The second half of the script illustrates how to use DurationCalculator to calculate a due date based on a schedule. Schedules enable you to apply a "filter" on future time, such as only including the days in a work week within the calculation. For example, if you apply a schedule "weekdays" (which only includes Monday through Friday) to your duration calculation, and the start datetime is Friday at 5:00 pm, when you add a duration of two days, your due date would be Tuesday at 5:00 pm. If you did not use a schedule, your due date would be Sunday at 5:00 pm. For additional information on schedules, see Creating and using schedules.
Using DurationCalculator to compute a simple duration
A simple duration is the number of seconds between two date times.
If no schedule is used then this is a simple time date subtraction. If a schedule is used, then the schedule is consulted to remove non-work hours from the computation. Suppose schedule "8-5 weekdays excluding holidays" is used. In this case, the number of work hours from noon Monday to noon Tuesday is nine hours. To compute a simple duration, initialize the global API DurationCalculator and call the calcScheduleDuration() method.
Using relative duration
Relative duration is very similar to simple duration except a piece of script is used to determine what parts of a day to remove from the difference calculation.
This script is stored in table cmn_relative_duration and can be examined by navigating to
. There are some example relative duration scripts in the out-of-the-box instance.A relative duration sys_id is passed to the method calcRelativeDuration() of the global API DurationCalculator class after initialization. When this method is called, the DurationCalculator object is passed to the relative duration script (stored in table cmn_relative_duration) as the variable calculator. So, the relative duration script you write and store in cmn_relative_duration has access to the executing DurationCalculator through the variable calculator.