I hesitate to call this post a “Best Practices” post, because who am I to prescribe a best practice? I won’t call it that. Instead this is a list of practices that I think are sane and maintainable over the long term.
I am currently on a project overhauling a Maximo instance that has gotten to the point where it is hard to maintain and debug, and there are bugs a plenty. It is a spiderweb of duplicitous workflows and automation script spaghetti code. This instance reveals some dangers of “low code” platforms. People seem to get the idea that they do not have to be concerned with clean programming practices or long term maintainability.
Write good clean code in Automation Scripts
This should be obvious, but it apparently is not. Just because we are using a script interpreter built into a web application doesn’t mean we should be lazy about it. Properly comment and structure your code.
Use good script and launchpoint names
Something that I like to do is name my scripts for the object and method they are working on.
ASSET.SAVE for example, or
WORKORDER.WORKTYPE.VALIDATE. This will make it easy to find an understand what these scripts are for. Name the launchpoint the same, because you need to migrate this as well and this will make it easier on you.
# Script: ASSET.SAVE
The example above shows a pattern I’ve been following. Keeping all logic related to asset.save in one script, instead of many with their own unique names, is much easier to maintain and debug. I have seen examples on my current project where seemingly no pattern was followed, and finding all the bits of pieces of their business logic is more of a scavenger hunt than it should be.
Using the Python function declaration
def myFunction(): I can use good program structure to keep all of the different things you might need clean and easy to modify or turn on or off. If you are just testing something, or the customer asks you to disable it, it’s as simple as removing or commenting out your function calls at the bottom of the script.
No matter what it is, even if it is the only thing the script does at the moment, just put it under a function declaration. It could help you in the future.
The Variables tab is pointless and bad
For reasons that I do not understand, there is a tab in the automation script editor called Variables. It is useless, and actually makes things much much harder to read and understand. Don’t use it. Python already has variables, and the MBO framework is available to you. Why use anything else? Keep things clean and easy to read.
Code reuse? Code reuse!!
You can and should employ code reuse in your automation scripts. Seasoned programmers understand this concept well, there are bits of code you may use in more than one place and it’s often appropriate to put these somewhere they can be called by other scripts or classes.
In Maximo these are referred to as LIBRARY scripts. IBM has a page on it here.
From their examples, they have a script called MULTIPLY.
They then use this script in another script. I’ll add more comments than their example has.
# here is an example of a debug logging
We name our library scripts clearly, like
When used appropriately, code reuse means you’ll have less code to maintain. That means less work. We all love less work, right?
Read Bruno’s site
Develop in Maximo for long enough and you’ll wind up on Bruno’s site. Bruno has a wealth of information available and the developers on my team use his site frequently. A link particularly relevant to this post is his automation scripting quick reference. I always have this open if I am writing automation scripts. I do not have a good memory.
And that’s it! There’s not much to it, I just wanted to put this out there. If you are just getting started using Maximo, or are new to using automation scripting, I hope something here gives you a head start. If you are used to Java customization then this will all be easy to pick up, and you probably didn’t need to read this anyway. For those that are coming to Maximo from a different background, I hope this helps you avoid future headaches.
BTW: If you are looking at using a Workflow for something, ask “hey can this just be an escalation or automation script instead?”. Asking that question often could save you a LOT of future headaches. :-)