Maximo Open Forum

 View Only

 Automatic Script to Prevent Work Order Closure Without Labor Hours Recorded

  • Customizations
  • Everything Maximo
  • Maximo User Groups
  • Work Management
Stevie Holloway's profile image
Stevie Holloway posted 07-25-2022 09:40
Hi,

Does anyone have an automatic script that prevents a work order's closure without labor hours recorded?

Thanks
Eric Godel's profile image
Eric Godel
I've typically seen the auto closure run off of an Escalation.  The escalation query checks for complete greater than a specific number of days, but it can also check for the existence of a labor record.

If I was going to do this in an automation script it would look something like this.
'''
launchpoint attribute Validate
Object:WORKORDER
Attribute:STATUS
'''

if mbo.getString("STATUS") == "CLOSE":
    laborSet = mbo.getMboSet("SHOWACTUALLABOR")
    if laborSet.isEmpty():
        service.error("configure","BlankMsg",["You must have a labor transaction to close this workorder."])

This would be jython, and there are so many different ways this could be written and other objects or launch points that could be used.  But this 4 line script should get the job done.

Eric
Nancy Lerner's profile image
Nancy Lerner
Stevie, you might try putting a condition on whichever of your work order statuses should not be selectable until labor is recorded.  The condition would include ACTLABHRS > 0. You might also want to include ISTASK = 0 so that users can complete tasks without putting labor on each individual task. If you already have an escalation that automatically closes completed work orders and you are trying to prevent that escalation from closing work orders that have no labor, you could use the ACTLABHRS > 0 requirement in the escalation condition, or you could put that condition on an escalation point that closes the work order and add a second escalation point that uses ACTLABHRS = 0 to trigger a notification to the work order owner or lead to remind them that they need to add labor to the work order.
Jason VenHuizen's profile image
Jason VenHuizen
Eric's answer is really good.  I would add to use the "getInternalStatus()" so it works for CLOSE and any aliases. I have also added a few safety checks in case the script was invoked in an unexpected context, just as good practice.

I didn't change it here, but as good practice you should add a message in the System Configuration > Platform Configuration > Database Configuration > Messages More Actions menu item and then reference the message group and key instead of embedding the message in your script.

The scriptConfig at the end is metadata included so you can deploy it with this VSCode extension, which vastly speeds up automation script development.

https://marketplace.visualstudio.com/items?itemName=sharptree.maximo-script-deploy

if mbo is not None and mbo.isBasedOn("WORKORDER") and mbo.getInternalStatus() == "CLOSE":
    laborSet = mbo.getMboSet("SHOWACTUALLABOR")
    if laborSet.isEmpty():
        service.error("configure","BlankMsg",["You must have a labor transaction to close this workorder."])

scriptConfig="""{
    "autoscript": "WORKORDER.SAVE.LABORCHECK",
    "description": "Check for labor before close.",
    "version": "",
    "active": true,
    "logLevel": "ERROR",
    "scriptLaunchPoints": [
        {
            "launchPointName": "WORKORDER.SAVE.LABORCHECK",
            "launchPointType": "OBJECT",
            "active": true,
            "description": "Check for labor before close.",
            "objectName": "WORKORDER",
            "save": true,
            "add": false,
            "update": true,
            "delete": false,
            "beforeSave": true
        }
    ]
}"""​