Automation Scripts: Compatibility with Maximo 7.6.1

I recently setup a Maximo 7.6.1 environment. After browsing the new user interface and investigating some of the new features I imported an old JavaScript-based automation script that I like to use. Upon executing this automation script I was met with an error on Line 1. This particular script is called remotely using OSLC.

Here is the message:

BMXAA7837E – An error occurred that prevented the <script> script for the null launch point from running.\n\tReferenceError: \"importPackage\" is not defined in <eval> at line number 1.

Here is the start of my script:

importPackage(Packages.psdi.server);
...

If you are like me you have many scripts that import Java packages so this was certainly alarming.

Why is this happening?

Maximo 7.6.1 uses a different scripting engine with the move to JDK 1.8. You may also encounter this with 7.6.0.6 (and newer) if using JDK 1.8. Given that, I wasn’t completely surprised my script didn’t work but I was surprised that there was not more written about encountering this message and what to do if your scripts no longer work after upgrading.

How do I fix it?

It turns out the answer was in an IBM document all along, but it took a while for me to use the correct phrase in my search engine in order to locate it. At the very end of the document, Maximo 76 Scripting Features, there is mention that the Rhino JavaScript engine was replaced with Nashorn (V8). I was aware that this was happening but I was not aware of what this change meant. It turns out that Nashorn does not permit the import of whole Java packages which sheds light on why I was getting that error above.

Thankfully there is a workaround for your old scripts! Add the following line to the beginning of your script:

load("nashorn:mozilla_compat.js");

This article references how to properly construct your script to take advantage of the new script engine. At least with the workaround above you can get your script working and improve upon it later.

Hopefully this will save you time when using your old JavaScript based automation script in a Maximo using JDK 1.8.