This article closes Part 7. We checked IBM’s attachment store page against the behaviour of Manage in the MAS 9.2 series, and we checked the method names on our test system. Where the page and Manage disagree, this page follows Manage.
How a script becomes the store#
The system property mxe.attachmentstorage names the store. Its value is either a Java class or
script:<NAME>:
mxe.attachmentstorage=script:MYSTORE- The name is case-sensitive. Write it as the script is stored, in upper case.
- The script needs “Allow Invoking Script Functions”. Without it, every call runs the whole script body and calls no function.
- An empty property falls back to
mxe.oslc.attachmentstorage, and when that is empty too, to the file store on disk.
The four functions#
A function that the script does not define is skipped without an error. Without
createAttachment or deleteAttachment, nothing happens in the store. Without getAttachment, no
data comes back.
| Function | What ctx holds | What the script does |
|---|---|---|
hasAttachment | the new name; the attachment record, or None for mail | checks whether the name is taken |
createAttachment | the name, the bytes and the MIME type; no attachment record | writes the bytes |
getAttachment | the attachment record, or only the URL name | returns the bytes with ctx.setAttachmentData(...) |
deleteAttachment | the attachment record only | removes the file |
The ctx object also offers every method of service, so ctx.error(...) raises an error from the
store.
hasAttachment: the name#
Before Manage calls hasAttachment, it has already checked the name: no invalid characters, no
trailing dot, and an allowed file extension from mxe.doclink.doctypes.allowedFileExtensions. The
script only has to check for a duplicate.
The name comes from ctx.getFileName(ctx.getAttachmentName()). The record from ctx.getMbo() can be
None, because the mail listener attaches files without one.
For a duplicate, the script has two choices:
- Give a new name with
ctx.setOverrideFileName("report-2.pdf"). Pass the plain name. - Report the duplicate with
ctx.setHasAttachment(True)and no new name. Manage then adds a hyphen and a time stamp in milliseconds before the extension.
Leave the top-level path to Manage. IBM’s page tells the script to put the value of
mxe.doclink.doctypes.topLevelPaths in front of the new name. Manage adds that prefix itself, in front of
the final name. A script that adds it as well gets it twice. IBM’s own example on the same page
leaves it to Manage, which is right.
An override name always wins in the 9.2 series. Calling setHasAttachment(False) first is not needed
for it.
deleteAttachment: the name comes from the record#
IBM’s page says that deleteAttachment finds the file name with the same methods as
createAttachment. It cannot. For a delete, Manage passes only the attachment record:
ctx.getAttachmentName() returns None, and ctx.getFileName(None) fails with a
NullPointerException. Read the name from the record:
def deleteAttachment(ctx):
name = ctx.getMbo().getString("urlname")
remove_file(name)remove_file stands for your own code. The example script further down IBM’s page does the same.
Two more details#
- The MIME type setter is spelled
setAttachmenMimeType, without the t in “Attachment”. On our test system, the correct spelling was missing. The getter isgetAttachmentMimeType. - Mail attachments can stream from the store. A script variable
datasourcewith the value 1 makes Manage read a mail attachment throughgetAttachmentwhen the mail needs its content.
Scripts that are not the store#
Every other script that writes or reads attachments should go through the store Manage has configured. A script that writes into the attachment folder on disk works only while the file store is in use. When the store moves to object storage or to a script, the script writes to a place nobody reads.
What IBM’s page gets wrong here#
| Topic | IBM’s page | What Manage does |
|---|---|---|
The name in deleteAttachment | the same methods as in createAttachment | the name is None there; read urlname from the record |
| The prefix for a duplicate | the script adds topLevelPaths | Manage adds it; adding it again doubles it |
setHasAttachment(False) before an override | required in the 9.1 series | an override wins in the 9.2 series either way |
| The function set | four functions | four, and a missing one is skipped without an error |
Article 33 of this series collects the corrections that matter most.
What comes next#
This ends Part 7. Part 8 is about development practice: naming and governing a script estate, testing, debugging with the warnings framework, and writing scripts in TypeScript.
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.
