Recently I was tasked with making one of 3 fields mandatory on a Maximo application. Doesn’t sound like rocket science, and in the past, my first thought would have been to work out a fun and complicated set of Conditional Expressions. Then I got to thinking, wouldn’t it be easier to just do an If-then statement somehow? Surely this automation scripting stuff can’t be as difficult as everyone always tries to make it. Well, I found out it’s not, and its amazingly powerful in a short amount of time.
What are the conditions that are needing to be met? We needed to make sure that before a WO was saved, either the Supervisor, Crew, or Owner was populated. The client will be using this information for reporting and Start Center portlets, so it was important to have the information on every Work Order.
Starting an Automation Script
As I am not now, nor have I ever been an automation scripting guru, I always have to play around in Dev environments to get the kinks worked out. I’ve been modifying others scripts for years but writing them from scratch was never my forte. No better time than the present to pick up the torch and run! I know enough to be dangerous, which is why I surround myself with some of the brightest people I know to help me out in a jam.
To get started I chose an Object Launch point. I figured it was a good choice as I’m working with Workorder object and not just on specific attribute. And to keep things simple, I usually name my launch point and the Automation script the same thing. Simple name for this one was SUPERCREWOWNER_OR.
I used some variables to make it easier to pull info in and pass it back out. To clean it up, they could all be just inbound, but it defaults to INOUT, so I just left it. I’m not passing any values back to the variables in my simple code.
The Code – Keep it Simple
Application modernization is a growing area of focus for enterprises. If you’re considering this path to cloud adoption, this guide explores considerations for the best approach – cloud native or legacy migration – and more.
Up front I will tell you, I am not a jython expert. Most all I have learned I have done so like many other coders, I have google the snot out of it until I found something close and made it work! This was no exception. I also leaned on some of my co-workers knowledge to make it as simple as I could. Instead of using OR logic though, it was easier to use NOT logic, as you will see in the code. The first requirement is that the Workorder has a Workorder number, then we move forward from there.
if wo is not None and (super is None and crew is None and owner is None):
The leading periods are to show mandatory spacing.
Essentially, if WONUM is NOT blank (required to save a WO), and all three of the other fields ARE blank, a custom error is thrown.
Note: To make the error work, you need to configure your custom error message. I will cover that in another post.
Once one of the fields is populated, the Work Order saves with no further interference.
Simple is Good
And that’s it! A simple automation script that throws an error and stops you from saving the record unless one of 3 fields are populated. Can Automation scripts be insanely more complicated? Yes, they can. Is it really necessary in all cases? Nope. This shows an easy solution to what could be an overly complicated set of multiple other tasks.
If you enjoyed this post, check out some of my other posts.
If you have any comments or questions, please leave a comment below!