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
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()