Maximo Open Forum

 View Only

 Calculate Estimated Duration ESTDUR on the WORKORDER Object

  • Analytics
  • Everything Maximo
Fitzroy Johnson's profile image
Fitzroy Johnson posted 06-17-2024 15:27

I would like to view the script that calculates the estimated duration (Attribute: "ESTDUR", Object: "WORKORDER"). 

Would anyone be able to point me to the script that does this calculation? 

Jade Warren's profile image
Jade Warren

Hello Fitzroy! 

We have approached this as follows.  We have a standalone script called DURATION that takes passed parameters and then populates a target field (in this case, ESTDUR) with a calculated value per our business rules.

Sample code to invoke the script looks like this:

from java.util import HashMap;
 
## get a hash-map to pass values to duration script
ctx = HashMap();
 
## determine how many milliseconds are between the estimated dates
## we use target for this calculation
time_diff = mbo.getDate("TARGCOMPDATE").getTime() - mbo.getDate("TARGSTARTDATE").getTime()
 
## put values into the hash-map
ctx.put("p_diff", time_diff);
ctx.put("duration_field", "ESTDUR");
ctx.put("mbo", mbo);
 
## call the duration script
service.invokeScript("DURATION", ctx);

The actual script body looks like this:

## determine the time differential from passed parameters
has_duration = False;
X = 0;
 
## first, see if we were passed a calculated millisecond value...
try:
    if (p_diff != None):
        X = p_diff;
        has_duration = True;
except:  xx = 1; ## catch and swallow exception
 
## next, see if we were passed start and finish values...
try:
    if (p_start != None and p_finish != None):
        X = p_finish.getTime() - p_start.getTime();
        has_duration = True;
except:  xx= 1; ## catch and swallow exception
 
## values for actually calculating duration from a time differential
elapsedhours = 0;
elapsedminutes = 0;
minuteinmillis = 1000 * 60;
hourinmillis = 1000 * 60 * 60;
 
## do the calculation
elapsedhours = X / hourinmillis
X = X - elapsedhours * hourinmillis
elapsedminutes = X / minuteinmillis
 
## if there is a duration, create in HH:MM format (front-fill minutes with 0 as needed)
if (has_duration):  p_duration = str(elapsedhours) + ":" + str(elapsedminutes).zfill(2);
 
## if there is a start, but no finish
elif (p_start != None and p_finish == None):  p_duration = "ONGOING";
 
## if there is no start
elif (p_start == None and p_finish == None):  p_duration = "NOT STARTED";
 
## default to empty
else:                                         p_duration = "";
 
try:
    if (duration_field != None):
        mbo.setValue(duration_field, p_duration, 11L);
except:  x = 1;  ## catch and swallow exception

Hopefully this is helpful!

--Jade

Craig Kokay's profile image
Craig Kokay

Hi Fitzroy,

Firstly, let's talk about ESTDUR as this has an impact on the script. 

ESTDUR is exactly that "the estimated duration of the time to complete the work order".  This is opposed to what the field help says, which is "Estimated remaining number of hours needed to complete the work."  I say opposed, as there is another field called REMDUR, which is the "remaining number of hours to complete the job". 

Normally, when you're dealing with a PM, then ESTDUR is set from the JOBPLAN.JPDURATION.  Yes! This should be done.  But it's still not calculated from the tasks and is usually manually set because the total time to do the work may include some built-in downtime or travel time.

In Maximo Scheduler, if you have time against each task, it will sum up those individual task times based on the linkages and say that is the ESTDUR.  Without this at the task level, it will use the ESTDUR (providing the target finish date has not been populated, noting the crossover from the job plan.  Here is some more info on the dates and their usage in Maximo Scheduler.

When the work order is generated from a PM that has a JPDURATION, the target finish is calculated as TARGSTARTDATE + ESTDUR.

If you create a work order without a Job Plan, then you should be setting the ESTDUR, but of course, this does not calculate the TARGCOMPDATE.

For the purpose of the script are you:

  • Calculating only from the TARGSTARTDATE --> TARGCOMPDATE = ESTDUR
  • Summing up the task durations to calculate the ESTDUR? It must be also noted that they are also work orders, and have the same exact properties for scheduling.
  • If the ESTDUR is changed, do you want it to update the TARGCOMPDATE?

Now, for those playing along, we have been remiss in not addressing the REMDUR and even Maximo Scheduler deals with that.