↓ Skip to main content
An ink and watercolour drawing of three things on a workbench: a lowered orange and white striped barrier across a short wooden track, a teal hand bell with a wooden handle, and two round paddle signs in a teal holder, one teal and one orange.

Errors, Warnings and Yes/No/Cancel From a Script

Maximo Automation Scripts - This article is part of a series.
Part 12: This Article
A script talks to the user in three ways: it stops the work with an error, it adds a warning, or it asks a question. Each way does something different to the record, and each has a trap that we saw on our test system. This article covers all three.

The previous article mapped every method of service. This one goes deeper into the methods that reach the user. We checked IBM’s pages against the behaviour of Manage in the MAS 9.2 series, and we ran the doubtful calls on our test system. Where the pages and Manage disagree, this page follows Manage.

Three ways to raise an error
#

WayWhen the error is raisedOUT variables
service.error(group, key) or (group, key, params)at once, on that linenot written back
the variables errorgroup, errorkey and paramsafter the script has endednot written back
any other exception, such as a typo in a nameat oncenot written back

All three stop the work that started the script. In a before save script, the save fails. After commit, the data is already saved, and the error is only logged. Article 7 shows that difference.

The first two raise your own message from the message table, by group and key. The params fill the places {0}, {1} and so on in the message text. The third raises a general script error, and the details go to the log.

Use service.error. It stops the script on the line that found the problem, so no later code runs by mistake. The variables still work, and they have one trap: the group variable is called errorgroup. IBM’s service pages write errorgrp. We set errorgrp with an errorkey on our test system, and the script ended normally, with no error at all.

Warnings
#

A warning leaves the work running. The user sees the message, and the save goes on. There are two ways to raise one:

  • service.setWarning(group, key, params) adds the warning to the record’s set at once. Pass None as params for a message without parameters.
  • The variables warngroup, warnkey and warnparams do the same after the script has ended. Neither IBM page names them.

Two traps:

  • A warning needs a record. In a cron task, or in a library script called without a record, setWarning fails with a NullPointerException.
  • Pass warnparams as a list. As a Java string array, the parameters are lost, and the warning takes the error params in their place. We saw that on our test system. A Jython list works.

A REST client gets the warnings in a warnings array of the response, each with its group, key and message. A common check before you raise a warning is if interactive:, so that background runs stay quiet.

Yes, no and cancel questions
#

A script can ask the user a question and act on the answer. In IBM’s design, the answer arrives in a second run of the same script:

The round trip of a yes, no or cancel question The round trip of a yes, no or cancel question
The round trip of a yes, no or cancel question

The parts that a script uses:

  • service.yncerror(group, key) or (group, key, params) raises the question. The message defines the buttons.
  • service.yncuserinput() returns the answer, and takes no arguments. Before an answer it returns YNC_NULL.
  • The answers are the constants YNC_NULL (-1), YNC_OK (2), YNC_CANCEL (4), YNC_YES (8) and YNC_NO (16). There is no constant for Close. The REST layer gives Close the value 1.

Manage stores the answer per user under the name of the script and its launch point. It finds the answer only on the server that holds the user’s session.

A common shape maps each answer to a function:

def ask():
    service.yncerror("asset", "assetpr")

def yes():
    global v, v_required
    v = "A0001"
    v_required = True

def no():
    global v, v_required
    v_required = False

if interactive:
    actions = {service.YNC_NULL: ask, service.YNC_YES: yes, service.YNC_NO: no}
    actions.get(service.yncuserinput(), ask)()

Four details make this shape work:

  • v must be OUT or INOUT. The functions set v and v_required. For an IN variable, both changes are lost.
  • The functions need global. In Jython, an assignment inside a function creates a local variable. Without the global line, yes() changes nothing that Manage reads.
  • Use .get with a default. A message that also has a Close button can answer 1, and a plain dictionary lookup then fails with a KeyError.
  • Check interactive first. In a run without a record, such as a REST script call, we saw yncuserinput() fail with a NullPointerException.

The question also reaches REST clients. The error response carries the question’s id and its buttons.

What IBM’s pages get wrong here
#

TopicIBM’s pagesWhat Manage does
The error variableerrorgrperrorgroup; errorgrp raises nothing
yncuserinputtakes group, key and paramstakes no arguments; the documented call fails with a TypeError
The interactive checka variable interactionthe variable is interactive; interaction does not exist
The yes/no examplesets the vendor through vworks only when v is OUT or INOUT
IBM Docs’ copy of the yes/no scriptshows the scriptnever calls yncerror or yncuserinput, so it asks nothing

The two IBM pages also disagree on the message type for a question: informational on one page, warning on the other. The server reads only the message’s buttons.

Article 33 of this series collects the corrections that matter most.

What comes next
#

Article 13 covers library scripts and function calls.

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

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.

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