↓ Skip to main content
An ink and watercolour drawing of an open orange wooden cantilever toolbox on a workbench, its trays fanned out to both sides. Eight compartments each hold one tool: a screwdriver, a hammer, pliers, a folding rule, a coil of wire, a magnifying glass, a paint brush and a pencil.

The Service Object: Every Method in the 9.2 Series

Maximo Automation Scripts - This article is part of a series.
Part 11: This Article
The service variable is the toolbox of every automation script. It raises errors, writes logs, calls other scripts, talks HTTP and reaches the integration framework. This page maps every method it has in the MAS 9.2 series, grouped by job, with the signatures that actually work.

This article opens Part 3 of the series. We checked IBM’s two tables of service methods against the behaviour of Manage in the MAS 9.2 series, and we called the doubtful ones on our test system. Where a table and Manage disagree, this page follows Manage. The next three articles go deeper into errors, library scripts and logging.

Where service exists
#

Manage creates a new service object for every run of a script, with or without a launch point. Two cases differ:

  • A function called from another script. A script with “Allow Invoking Script Functions” is loaded once. When another script calls one of its functions, that function runs without the normal variables, so service is undefined inside it.
  • Integration, role and attachment scripts. They get an extended service object as the argument of their function, usually named ctx. It has every method below and more. Later parts of this series cover them.

Errors, warnings and questions
#

MethodWhat it does
error(group, key)raises the message group/key and ends the script at once
error(group, key, params)the same, with message parameters
setWarning(group, key, params)adds a warning to the record’s set; the script continues
yncerror(group, key), yncerror(group, key, params)asks the user a yes, no or cancel question
yncuserinput()returns the user’s answer, and takes no arguments
YNC_NULL, YNC_OK, YNC_CANCEL, YNC_YES, YNC_NOthe possible answers

setWarning needs a record. Article 12 covers all of these in depth.

Logging
#

MethodWhat it does
log(msg)writes at DEBUG or INFO, depending on the script’s log level
log_debug, log_info, log_warn, log_error, log_fatalwrite at that level, as (msg) or (msg, error)
logError(msg)writes at ERROR
getLogger(name)returns any logger by name, for example maximo.integration

Each call goes to the log at once. print output appears only after the script ends. There is no isLoggingEnabled(), although IBM’s best-practice pages use it: our test call failed with an AttributeError. Article 14 covers logging.

Calling other scripts
#

MethodWhat it does
invokeScript(name)runs a library script with the caller’s record and returns its variables
invokeScript(name, context)runs it with the variables in the map context, and copies its variables back into that map
invokeScript(name, function, args)calls one function of the script and returns its result

An unknown name raises an error. An inactive script quietly does not run. Article 13 covers library scripts.

Records and properties
#

MethodWhat it does
getMbo(), getMboName()the record of the run and its object name, or None
getScriptName()the name of the script; in a library script, the library’s name
getMboSet(name, userInfo)opens a new set of that object, with its own transaction
getProperty(name)reads a system property, or None when it is not set

A set from getMboSet lives outside the record’s transaction. The script must save it if it changes it, and close it in every case. Article 15 explains why that is rarely the right set.

JSON
#

MethodWhat it does
tojsonobject(text)parses text into a JSON object
tojsonarray(text)parses text into a JSON array
jsonToString(object)turns a JSON object into text
jsonarrayToString(array)turns a JSON array into text

These use the JSON library that ships with Manage, so they work in Jython, where the Python json module is missing. Article 2 shows that.

HTTP
#

MethodWhat it does
httpget(url), httpget(url, user, password)GET, returns the response as text
httppost(url, data), httppost(url, user, password, data)POST of text, returns text
httpgetasjson(url, user, headers, password)GET with headers, returns JSON
httppostasjson(url, user, password, headers, json)POST of JSON with headers, returns JSON
httpgetasbytes(url, user, password)GET, returns the raw bytes
httppostasbytes(url, user, password, data)POST of bytes, returns bytes

The HTTP methods have four traps:

  • httppostasjson takes five arguments. IBM’s tables show four, and that call fails with a TypeError. Our test showed it. The headers string comes fourth.
  • httpgetasjson puts the headers before the password. The odd order is right.
  • Send a content type. A POST without a Content-Type header goes out as text/xml. Pass "Content-Type:application/json" in the headers when the server checks it. Headers are written as name1:value1,name2:value2.
  • Character sets differ. httpget decodes the answer with the server’s default character set. The POST methods use UTF-8.

httpgetasbytes returns bytes. IBM’s description says text, which is copied from httpget.

Integration
#

MethodWhat it does
invokeEndpoint(endpoint, metadata, data)calls an integration endpoint with text or bytes, returns the same type
invokeStringEndpoint, invokeByteEndpointthe same, under explicit names
invokeChannel(name)calls an invoke channel with the script’s record
wsinteraction(name)runs an integration interaction with the script’s record
raiseSkipTransaction()tells the integration framework to skip this message
invokeWorkflow(name)starts a workflow process on the script’s record

Be careful with invokeWorkflow. When the start fails, the method swallows the error, writes nothing to the log, and rolls back the record’s set. The script gets no sign at all. Check the result yourself, for example by reading the workflow assignment afterwards.

Classic UI
#

MethodWhat it does
closeDialog()closes the current dialog
openURL(url, newWindow)opens a URL, in a new window when asked
launchDialog(dialogId)opens a dialog
displayMessage(group, key, params)shows a message box; the script continues
webclientsession()returns the session of the classic UI, or None

All five need a request from the classic UI. In a REST call, a cron task or any other background run, they do nothing and raise no error. Errors inside them go to the script’s log only.

What IBM’s tables get wrong
#

Four signatures in IBM’s material fail when called. We called each of them on our test system:

IBM’s pagesWhat happensUse instead
errorgrp with errorkeythe script ends normally, with no errorerrorgroup, or service.error()
httppostasjson with four argumentsTypeErrorfive arguments, headers fourth
yncuserinput(group, key, params)TypeErroryncuserinput()
service.isLoggingEnabled()AttributeErrorthe logger’s own check, see article 14

The tables also leave out fourteen methods that exist: invokeWorkflow, getMboSet, getProperty, getLogger, getScriptName, getMbo, getMboName, logError, launchDialog, displayMessage, webclientsession, wsinteraction, invokeStringEndpoint and invokeByteEndpoint, plus the five YNC constants. Article 33 of this series collects the corrections that matter most.

What comes next
#

Article 12 covers errors, warnings and yes, no and cancel questions from a script.

IBM’s own pages are the reference to keep next to this series:

The complete inventory of what the script engine does without documentation 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.

Maximo Automation Scripts - This article is part of a series.
Part 11: This Article