We build the Manage-side scripts of our own products this way. Every rule below comes from a measurement on our test system, on the MAS 9.2 series, or from a build that failed without it.
What Manage runs#
Article 2 showed the JavaScript engine of Manage. For a build, five facts decide everything:
- ES5 syntax.
let, arrow functions, template strings, classes, default parameters, destructuring, spread,for…of, generators,**and?.do not compile. - The ES5 library.
Map,Set,Symbol,Array.prototype.includesandfind,Object.assignandPromiseare missing at run time. - One source text per script. Manage has no module loader. Whatever a script needs has to be in its own source.
- Globals in and out. Manage puts
requestBody,userInfoand the other variables into the global scope, and readsresponseBodyfrom there after the run. - No strict mode. With
"use strict", the assignment toresponseBodythrows a ReferenceError, because strict mode forbids assigning a name that was never declared.
Java classes come through Java.type. MXServer, for example, is no global.
The build, rule by rule#
| Rule | Why |
|---|---|
| Declare the injected globals in TypeScript | the compiler and the editor then know requestBody, responseBody and userInfo |
| A small typed facade for the Maximo classes the scripts use | types for MboSet, Mbo and UserInfo, written by us, with no IBM package |
| Bundle each script into one file | Manage loads one source text, with no module loader |
| Type check against the ES5 library only | Map or includes fail at compile time, before Manage ever sees them |
| Parse every output file as ES5 | any newer syntax fails the build; bundlers emit some of it even from ES5-style sources |
Fail on "use strict" | it turns the responseBody assignment into a ReferenceError |
Check that responseBody is assigned at top level | a wrapper function would hide the assignment from Manage |
A version header in a comment, such as /*! MYSCRIPT 1.4.0 */ | an administrator can read the version in the Automation Scripts application |
The parse step is the one that catches the most. Our bundler has no ES5 target, and it writes some
ES2015 forms on its own, such as the shorthand { key } for { key: key }. A build that only type
checks lets them through, and Manage then refuses the script at install. So the sources keep to
var and function, and the build parses its own output before anything else sees it.
A script entry then looks like this:
declare var requestBody: string | undefined;
declare var responseBody: string;
function answer(body: string | undefined): string {
return JSON.stringify({ received: body ? body.length : 0 });
}
responseBody = answer(typeof requestBody === "undefined" ? undefined : requestBody);The typeof test matters. On a GET, requestBody does not exist at all, and reading it would throw.
Testing outside and inside Manage#
The facade makes the scripts testable without Manage. A fake MXServer answers getMboSet with
in-memory sets, and the tests run with an ordinary test runner. That covers the logic: the rules,
the edge cases, the error paths.
Inside Manage, the script handler of article 22 calls the installed script with a request, and the answer shows whether the built file behaves like the source. Article 30 shows that second way of testing.
When it pays, and what it costs#
TypeScript pays for larger scripts, for helpers shared between scripts, and for a team that wants reviews and tests in a pipeline. A short object script on one event stays simpler in Jython, as article 2 recommends.
The costs are real:
- A build step. The source of truth moves out of Manage. An edit in the Automation Scripts application is overwritten by the next install.
- Line numbers. An error message names a line of the built file. Keep the build readable, without minification, so that the line still points at code a person can read.
- The ES5 discipline. Sources look older than modern TypeScript, because the target is older.
The full build, with its checks and its tests, is described in detail in our member area.
What comes next#
This ends Part 8. Part 9 is the reference: where IBM’s script documentation is wrong, what the script engine does that nobody documented, and a quick reference card.
IBM’s own pages are the reference to keep next to this series:
- Automation scripts in the IBM Maximo Manage documentation.
- All about Maximo scripting, IBM’s scripting guide on GitHub.
The complete list of corrections, with the evidence for each one, is in our member area. Members get access on request, so get in touch if you want it. If you want help with the scripts in your own Manage, our services page shows how we work.
IBM and Maximo are trademarks of International Business Machines Corporation, registered in many jurisdictions worldwide.
