Display Maximo Messages in Jython

It is often useful to provide a user some visual feedback if a script runs ok or ends with an error message. Maximo provides a complex message system which can be found in its Database configuration. Using this message system you can create message boxes like the following one.

messagebox1

In this post I will show you step by step the usage of the message system.

Scenario

The scenario we want to implement is to check the Priority field within a Workorder. If the Value is larger than 50 we would like to inform the user by a message and not allow to save the record.

The implementation needs the following elements:

  1. A message defined in Maximo
  2. A script with an Attribute Launchpoint

Preparation of Messages in Database Configuration

Start the Database Configuration by:

Goto –> System Configuration –> Platform Configuration –> Database Configuration

In the “Select Action” Menu select “Messages”. You will see an editor Window where you can edit all messages of the Maximo application.

messagebox2

To add new messages press the “New Row” button. A big input screen appears:

messagebox3

A couple of important fields in this screen need some clarification:

  • Message Group: Maximo has a couple of predefined Messages Groups for the different applications or other grouping characteristics. You can either add your message to an existing group or define your own group. An own group can specially help you if you have a couple of related messages for the same context.
  • Message Key: The unique Message Key is an important identifier to address a specific message from your script later on. Therefor it should be a short meaningful specification of what the message means. I prefer upper camel case conversion like “InvalidPrio”. The Message Key together with the Message Group uniquely identifies the message.
  • Display Method: Can be ‘MSGBOX’ or ‘STATUS’. The ‘MSGBOX’ display a standard popup window displaying the message and a set of customizable buttons. The ‘STATUS’ displays the text above the tool bar and does not require user intervention
  • Message ID Prefix: Should be “BMXZZ” which is the pre-defined message prefix  for all custom messages.
  • Message ID Suffix: Specification of the Severity:
    • I = Informational
    • W = Warning
    • E = Error
  • Display ID?: If checked the ID BMXZZ… will be shown in the Messagebox.
  • Value: The Message text. The message Text can include placeholders {0}, {1}, {2} and so on for replacement parameters. I will show you later how to script them.

After clicking OK the new message is immediately available. No Database configuration is required at this point.

Creating the Attribute Launchpoint and the Script

GoTo –> System Configuration –> Platform Configuration –> Automation Scripts

In the “Select Action” Menu select “Create –> Script with Attribute Launchpoint”.

Fill in the following dialog and press Next:

messagebox4

In the following dialog enter the script name and press next:

messagebox5

In the final configuration screen enter the following sample code:

woPriority = mbo.getInt("WOPRIORITY")
if woPriority > 50:
    # Raise an error using a message
    errorgroup = "workorder"
    errorkey = "invalidPrio"

Please notice, that I never use In/Out variables for my scripts, because they make scripts less readable and will cause more issues with undefined variables in Eclipse. As a result I need to get the woPriorty value in line 1.

The important code for the message handling is in lines 4 and 5. We only set the explicit variables errorgroup and errorkey to existing values in the Message Database and that’s all. But how do we show the message to the screen? There is no code for this? The answer is: Maximo will do this for us. We only have to set the two variables at the end of our script. As you see this is also one big limitation, since we can use messages usually only at the end of our script.

If you now save the script and test the Workorder application you should get a message if you enter a Workorder Priority higher than 50.

messagebox6

Sending a message with parameters

What is still missing how we can replace parameters in messages. Let’s assume we have the following message:

Workorder {0} could not be processed because invalid Priority {1} has been specified.

To address such an message from our script we need the following code:

woPriority = mbo.getInt("WOPRIORITY")
woNumber = mbo.getString("WONUM")
if woPriority > 50:
    # Raise an error using a message
    errorgroup = "workorder"
    errorkey = "invalidPrio2"
    params=[woNumber, str(woPriority)]

The trick is the params variable which is a list of replace values for {0} and {1}. The final result looks as follows:
messagebox7

 

Attention:
Message boxes are displayed by throwing exceptions from Jython. If your script updates fields in a Mbo currently displayed the exception can have the effect that the fields in the applications are not updated on the screen. Please consider the Messagebox as the source of the issue if you see this behaviour!

11 comments

  • Thank you ! so helpful

  • Thanks …
    Its very helpful..
    But i have a query.. In previous version of Maximo we use get message box as a popup wen we get an exception.. but now we are getting in the filed it self.. but how can make an exception in to a pop up message

    • Good point. Where you get your message depends on the launchpoint you are working on. In my scenario I used an attribute launchpoint with the result that the message occurs bound to a single attribute validation. If you are using an Object launchpoint or a Action launchpoint instead the message is not bound to a special attribute and it will display as a pop up message.

      • Thanks Mstroske…
        I got your point.. as you are doing with attribute launchpoint, message is coming with in the attribute filed.. and when we do with object and Action launchpoint, message will be displayed as POPUP.. even i have observed the same….

        But In OLD version of ICD (TSRM 721) .. even attribute lauchpoint message used to come as pop up..
        ..
        so, what ever we have observed in ICD753, is new feature r is there any other way to achieve old version functionality

  • Scripts in Self Service offerings are considered “validation” scripts. Setting errorgroup, errorkey & params throws an SCCD 751 error message box which contains my message (see below). Launch point scripts don’t do this. How can I eliminate the Tpae text and show just my Msg ID & Text? When the user dismisses the box with OK, the user must be able to correct the fields and push the Add to Cart button. “Error” box allows this (good). “Warning” box Adds to the Cart (not good). An alternate way to achieve the same is fine too – need to inform the user and return to the offering screen, or cancel the offering and return the user to the Self Service menu. Thanks.
    ====================
    CTGRC3318E – This offering has the following errors:
    Validation script OTC_FW_INST_IP_EMAIL:psdi.util.MXApplicationException: . Contact the system administrator.

  • Correction to previous note:
    =======================
    CTGRC3318E – This offering has the following errors:
    Validation script OTC_FW_INST_IP_EMAIL:psdi.util.MXApplicationException: “My Msg ID – My Msg Text”. Contact the system administrator.

  • How do you get the result of a OK / Cancel or Yes/No result in an Automation Script?

  • Hello Mathias, excelent note. In my case I have a custom msgbox message with cancel,yes and no button checked, but when the script automation that I did launchs the message the buttons are not visible just and “Ok” button. This is on Maximo 7.5.0.4.

    Thanks in advance for your comments.

    Regards

    Pablo

  • Pingback: Maximo Scripting – Warnings and Errors | IBM Maximo Dev Blog

Leave a Reply

Your email address will not be published.