Same answer as on the TechXchange, but here for others benefit as well.
# The inspection form number you want to apply.
inspection_form = "1001" # In the MAXDEMO database, this is the Portable Ladder Inspection
def main():
# Check that this is being invoked from an Object save and that the object is a WORKORDER and not a task.
if ("mbo" in globals() and mbo.isBasedOn("WORKORDER") and not mbo.getBoolean("ISTASK") and mbo.toBeAdded()):
# This is here for demonstration purposes, to show how you might filter this to specific work types.
if(mbo.getString("WORKTYPE") == "CM"):
mbo.setValue("INSPFORMNUM", inspection_form)
# Call the main function, ensuring there is a single entry point to the script.
main()
scriptConfig="""{
"autoscript": "WORKORDER.APPLY.THA",
"description": "Apply task hazard analysis to every work order created.",
"version": "1.0.0",
"active": true,
"logLevel": "ERROR",
"scriptLaunchPoints": [
{
"launchPointName": "WORKORDER.APPLY.THA",
"launchPointType": "OBJECT",
"active": true,
"description": "Apply task hazard analysis to every work order created.",
"objectName": "WORKORDER",
"save": true,
"add": true,
"update": false,
"delete": false,
"beforeSave": true
}
]
}"""