Maximo Open Forum

 View Only

 Automation script to add labor hours more easily.

  • Work Management
sun kim's profile image
sun kim posted 06-16-2025 12:25

I have a user that all they do it enter time for one labor code for a group of people. 99% of the time, they are entering a labor code, today's start and end date, and 0.5 hour on the work order and closing out the status. Its a stack of paper she goes through. I wanted to auto fill some of the fields, but labor hour seems to error out for various reasons. It wants me to select the calendar and select the date and will not take an auto fill value. I also had to change the premium pay code in app designer to PPCRAFTRATE.PREMIUMPAYCODE (https://login.ibm.com/oidc/sps/auth?client_id=YWFlMTBjZDktMjEwYi00

Ibm remove preview

 )

https://login.ibm.com/oidc/sps/auth?client_id=YWFlMTBjZDktMjEwYi00

Ibm remove preview
View this on Ibm >
Ibm remove preview
View this on Ibm >

). Maximo seems to want me to enter data in via the UI, and there's some background stuff going on, perhaps with the class files associated with the various attributes? Is there a way I can auto fill with an automation script?

sun kim's profile image
sun kim

Here's the automation script I ended up with using Gemini Pro 2.5 (June 2025) and some gentle nudging. Biggest issue for me was initially using LABTRANS as the context rather than WORKORDER. And the sigoption.

User still has to save the entry. Some default values are entered but they are all editable before saving.

I have an Object Launch Point on WORKORDER with a conditional when you first create it to limit it to a specific security group. 

I had to create a sig option to grant that button to a security group: https://bportaluri.com/2014/06/invoke-action-when-button-is-pressed.html

I also created an attribute launch point to with a different automation script name which can also be called from the single automation script that handles any change in start date. 

I've tested it with the following scenarios but the script may not work correctly in all situations.

Standard Scenarios

  • Test 1: The "Happy Path"

    • Click the "Add Houskpr Labor Hour" button.

    • Do not change any values.

    • Save the Work Order.

    • Expected Result: The Work Order saves without error.

  • Test 2: Modify Hours (Your original test)

    • Click the button.

    • Change Regular Hours from 0.5 to 2.

    • Tab out of the hours field.

    • Expected Result: The End Date and/or End Time should update automatically to be 2 hours after the Start Date/Time. The Work Order should save without error.

  • Test 3: Modify Start Date

    • Click the button.

    • Change the Start Date to yesterday's date using the calendar lookup.

    • Tab out of the date field.

    • Expected Result: The End Date should update to yesterday, and the End Time should be 30 minutes after the Start Time. The Work Order should save without error.

  • Test 4: Modify Start Date, then Modify Hours

    • Click the button.

    • Change the Start Date to three days ago.

    • Tab out. The End Date should adjust.

    • Now, change the Regular Hours to 4.

    • Tab out of the hours field.

    • Expected Result: The End Date and Time should adjust again to be 4 hours after the new Start Date/Time. The Work Order should save without error.

Edge Cases

  • Test 5: Zero Hours

    • Click the button.

    • Change Regular Hours to 0 and tab out.

    • Expected Result: The Start Date/Time and End Date/Time should become identical. The Work Order should save.

  • Test 6: Deleting the Record

    • Click the button to add a new labor line.

    • Before saving the Work Order, click the "Mark Row for Delete" (trash can) icon on the new line.

    • Save the Work Order.

    • Expected Result: The Work Order saves without error, and the new labor line does not get created.

  • Test 7: Multiple Clicks

    • Click the "Add Houskpr Labor Hour" button three times in a row without saving.

    • Expected Result: Three new, identical labor lines should appear. The Work Order should save without error.

from psdi.mbo import MboConstants 
from psdi.server import MXServer 
from java.util import Date

# --- Main Script Logic ---

# The script checks the launchPoint name to determine which event triggered it.

# ==> TRIGGER 1: The 'Add  Labor' button is clicked.
if launchPoint == "HOUSKPR":
    service.log("HOUSKPR script: Running for ACTION launch point.")
    
    # Get the Work Order context
    current_wo_mbo = None
    if 'mbo' in globals() and mbo is not None and mbo.getName() == "WORKORDER":
        current_wo_mbo = mbo
    elif 'mbo' in globals() and mbo is not None and mbo.getOwner() is not None and mbo.getOwner().getName() == "WORKORDER":
        current_wo_mbo = mbo.getOwner()

    if current_wo_mbo is None:
        raise Exception("Work Order context not found.")
        
    # Add a new LABTRANS row and set initial values
    labtrans_set = current_wo_mbo.getMboSet("LABTRANS") 
    new_labtrans = labtrans_set.add()

    # Set the initial start time and hours.
    # We do not need to set the finish time manually.
    now = MXServer.getMXServer().getDate()
    new_labtrans.setValue("LABORCODE", "HOUSKPR", MboConstants.NOACCESSCHECK)
    new_labtrans.setValue("REGULARHRS", 0.5, MboConstants.NOACCESSCHECK)
    new_labtrans.setValue("STARTDATE", now, MboConstants.NOACCESSCHECK)
    new_labtrans.setValue("STARTTIME", now, MboConstants.NOACCESSCHECK)
    
    # Command the new LabTrans object to calculate its own finish date/time based on the values above.
    new_labtrans.setValuesForFinishDtTm()

    # Set other required fields from the parent Work Order
    new_labtrans.setValue("ORGID", current_wo_mbo.getString("ORGID"), MboConstants.NOACCESSCHECK) 
    new_labtrans.setValue("SITEID", current_wo_mbo.getString("SITEID"), MboConstants.NOACCESSCHECK)
    new_labtrans.setValue("REFWO", current_wo_mbo.getString("WONUM"), MboConstants.NOACCESSCHECK)

# ==> TRIGGER 2: The 'Regular Hours' field is edited by a user.
elif launchPoint == "HOUSKPR_RECALC":
    service.log("HOUSKPR script: Running for ATTRIBUTE launch point on REGULARHRS.")
    
    # Command the LabTrans object to recalculate its own finish date/time
    # based on the new hours the user just entered.
    mbo.setValuesForFinishDtTm()

# ==> TRIGGER 3: The 'Start Date' field is edited by a user.
elif launchPoint == "HOUSKPR_STARTDATE":
    service.log("HOUSKPR script: Running for ATTRIBUTE launch point on STARTDATE.")

    # Command the LabTrans object to recalculate its own finish date/time
    # based on the new start date the user just entered.
    mbo.setValuesForFinishDtTm()