September 1, 2011

How to create a custom message and display it in a Maximo application

This entry is part of the Maximo Java Development series.

A typical need during Maximo application customization is the ability to display a message on the GUI.

The first step is to define the custom message. Open the Database Configuration application and select Messages for the Action menu. Create a new entry filling the required info:
  • Message Group: Messages can be categorized in groups. I typically put here the name of the customer that I'm working on. This allows to quickly list all the custom entries.
  • Message Key: Unique ID of the message. This field together with the MSGGROUP uniquely identifies the message. I typically use a short descriptive name of the message like 'InfoMsg' or 'ErrorMsg'.
  • 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: Unique ID of the message. The typical format of custom messages is BMX[CC][NNNN][T] where [CC] is a two letters code that identifies your customization, [NNNN] is a four digits number and [T] is the type of message and can be E (Error), W (warning) or I (Info). Maximo suggest to use [CC]='ZZ' for custom messages. For example I have started my custom enumeration with code BMXZZ1001I.
  • Value: Text that will be displayed. Use {N} tags for parameters to be replaced at runtime (see example hereafter). Use \n to insert a newline.
Here is a screenshot of the new message.


Now that you have defined your message in the database it's time to show it.
The technique to display the message is different whether you are in an AppBean or in a Mbo class.

AppBean
If you are in a custom application bean class (extending AppBean) those two Java lines will bring up the custom message box.

String params[] ={"Hi there!"};
clientSession.showMessageBox(
  clientSession.getCurrentEvent(), "MyGroup", "HelloMsg", params);

As you can see the {0} tag in the message will be replaced with the string 'Bruno' defined in the params array. Obviously it is possible to define multiple tags.

It is also possible to display this message box when an exception is thrown. For example the following two rows will display the same message but will also log a stacktrace in the system logs.

String params[] ={"Hi there!"};
throw new MXApplicationException("MyGroup", "HelloMsg", params);

Mbo/MboSet
If you are in an Mbo or MboSet (businessobject project) you can 'attach' the message to the MboSet with the MboSet.addWarning(MXException e) method.

String params[] ={"Hi there!"};
this.addWarning(new MXApplicationException("MyGroup", "HelloMsg", params));

Alternatively it is possible to throw an MXApplicationException like this.

String[] params = {"Hi there!"};
throw new MXApplicationException("MyGroup", "HelloMsg", params);

36 comments:

  1. Hi,
    Thanks for this valuable information.
    But, how can we display this message using the GUI Application Designer & Conditional Properties.

    ReplyDelete
  2. I do not think this is feasible :-(

    ReplyDelete
    Replies
    1. Maybe we can use automation script to display the message, somewhat easier than java coding.

      Delete
    2. http://nordlicht.co/maximo/maximo-display-error-message-using-automation-scripts/

      Delete
  3. Hi all,
    I want to custom by extend PO class, like this:

    public MboRemote createPOLineFromPR(MboRemote fromPR, MboRemote fromPRLine, MboSetRemote poLines) throws MXException, RemoteException
    {
    if(!getString("SITEID").equals(fromPR.getString("SITEID")))
    {
    String params[] ={"The siteid not match!"};
    showMessageBox(clientSession.getCurrentEvent(), "MyGroup", "HelloMsg", params);
    return null;
    }

    return toPOLine;
    }

    But, the error at "showMessageBox(clientSession.getCurrentEvent(), "MyGroup", "HelloMsg", params);"
    Could you please tell me how to fix.
    Thank so much

    ReplyDelete
  4. The showMessageBox method is defined in application beans (extending psdi.webclient.system.beans.WebClientBean) and is not available in MBO beans (extending psdi.mbo.Mbo). In other words it can be used only in web classes, those contained in maximouiweb project.
    If you want to do a similar thing in an Mbo data bean you have to throw an exception.
    Look at this code snippet:

    String[] params = {"The siteid not match!"};
    throw new MXApplicationException("MyGroup", "HelloMsg", params);

    Please tell me if this works.

    ReplyDelete
    Replies
    1. Thanks Bruno Portaluri,

      It works in your case.

      MXApplicationException always stop and do nothing after show the message.

      But, I want to run next step after show the message.

      Can we have other ways?

      Thanks again for reply

      Delete
  5. This ca be achieved by adding a warning message in the mbo code.

    e.g.
    mboremote.getThisMboSet().addWarning(new MXApplicationException("commlog","AccountManagerRoleNoLocationSpecified", params));

    ReplyDelete
    Replies
    1. Great tip Megha!
      I have updated the article.

      Delete
  6. I need show defsite in startcenter in the blue bar:

    Welcome, MAXADMIN
    Site BEDFORD

    Do you know it?

    Thanks,

    Seba

    ReplyDelete
    Replies
    1. I would think you might be able to achieve this using Database Configuration > Messages and setting a different value for:
      Message Group: login
      Message Key: welcomeusername

      Delete
  7. Hi Bruno,

    I want an OK message to be displayed. But the processing should also continue. It should be in field class also. Is mboset.addWarning a solution for this?? But if you do this, it will affect at the time of save right?

    ReplyDelete
    Replies
    1. The addWarning will continue without stopping the execution and it should not affect the save.
      Can you please try and confirm this?

      Delete
    2. Yes it works . Its not stopping save. But now there is a new requirement. Put the same warning in bean class.

      I added the same line of code in bean class.....BUT NO POP came up plus its coming at the time of save. I want this message at the time of click of new row button.

      Delete
  8. Hi Bruno,

    Great Post.

    I want to show a msg box while creating WO from SR(SR App), that shows Yes/no that displays if there is an open WO for that SR. Now if I select Yes, another WO is created and if I select No, WO is not created.

    I am entending the App Bean.

    I need to to know, How do I code for the YES and NO Selection

    ReplyDelete
    Replies
    1. This should solve your problem: http://maximodev.blogspot.com/2012/10/how-to-display-yes-no-ok-cancel-dialog-box-user-input.html

      Delete
  9. Hi Bruno,

    Can We show above message for specific user.

    ReplyDelete
    Replies
    1. I think you can retrieve the current logged in user calling MboSet.getUserInfo().getUserName() method and perform some logic.

      Delete
  10. well done Bruno, just used it in my java custom code ;-)

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. Hi Bruno..I have a custom message with two buttons OK and CANCEL.If OK is clicked i need to perform a action and if CANCEL is clicked i need to perform another action through customization.How to capture the action performed?please help

    ReplyDelete
    Replies
    1. Bruno i wrote my code like this and my below messagebox displays two buttons OK and CANCEL but not YES/NO

      clientSession.showMessageBox(clientSession.getCurrentEvent(),"c_vehapp","CustomMessageUpdate",arg);

      WebClientEvent event = clientSession.getCurrentEvent();

      int msgRet = event.getMessageReturn();

      and basing on the value in the msgRet by using another if,else condition i am performing someother action... but the problem here is

      the value in msgRet is -1 for the click performed on either OK or CANCEL...

      do i need to add any extra code to capture my event...i am a starter of maximo

      please help me how to capture the value of the event and procced further.

      Delete
  13. Hi Bruno,

    My requirement is to display YES,NO exception in on click of change status button.
    If YES, is clicked, status should not be changed, if NO is clicked status should be changed.
    I have written the following code, but it goes into infinite loop,means the dialog box repeats itself again and again:

    if(getMbo().getUserInfo().isInteractive()) {
    int userinput = MXApplicationYesNoCancelException.getUserInput("SingleWOStatusChange", MXServer.getMXServer(),getMbo().getUserInfo());

    switch (userinput)
    {
    case MXApplicationYesNoCancelException.NULL:
    if (wonums != "" ) {
    Object[] params = {wonums};
    throw new MXApplicationYesNoCancelException("SingleWOStatusChange", "wms", "validateLimitPOContract",params);
    }
    else{
    break;
    }
    case MXApplicationYesNoCancelException.NO:
    break;
    case MXApplicationYesNoCancelException.YES:
    no_times_contr_ref_warning_shown = 0;
    Utility.sendEvent(new WebClientEvent("dialogcancel", app.getCurrentPageId(), null, sessionContext));
    return EVENT_HANDLED;
    }
    }
    } //Try
    catch (MXException e)
    {
    if(e instanceof MXApplicationYesNoCancelException)
    {
    if(this.no_times_contr_ref_warning_shown==0)
    {
    no_times_contr_ref_warning_shown++;
    throw e;
    }
    }
    else
    throw e;
    }//catch

    Please tell me how to rectify it.

    ReplyDelete
  14. Is there a way to display a pop-up warning message prior to the user login page?

    ReplyDelete
  15. Hello,

    I want to simulate 'dialog close' event in the automation script. I believe this is the piece of code that can help me -

    Utility.sendEvent(new WebClientEvent("dialogclose", app.getCurrentPageId(), null, sessionContext));

    But I understand that app & sessionContext objects are not implicitly available to scripting framework.

    How can I achieve this using automation script?

    ReplyDelete
  16. Referring from the DeveloperWorks Forum, some user posted below code -

    from psdi.webclient.system.controller import SessionContext, Utility, WebClientEvent
    from psdi.webclient.system.session import WebClientSessionManager


    uisessionid = "12"
    c = WebClientSessionManager().getWebClientSession(uisessionid)
    Utility().sendEvent(WebClientEvent("dialogok", c.getCurrentPageId(), None, SessionContext(c)))

    it works if I hardcode the uisessionid in the script as mentioned above. Is there any way to achieve this dynamically using automation script?

    ReplyDelete
  17. Hi Bruno,
    I wanted to populate warning message when user modifies the field. Is this possible through Automation Script?

    ReplyDelete
  18. I also need help on question posted by kirankumar,
    Can you please help.

    ReplyDelete
  19. Hi Bruno,

    I want to display a warning message on a dialog when i click on the OK button. But I am getting the message after the dialog is closed. Please Help...
    Can this be done in maximo?
    As I have not seen any scenerion where a warning message is thrown on a dialog on the click of OK button.

    ReplyDelete
  20. is someone can have a simple example to display a msg ? i am not developper and i would like to see a msg

    ReplyDelete
  21. This comment has been removed by the author.

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. Hi Bruno,

    I want to keep my dialog displaying when i click on OK bouton

    Can you help me please

    ReplyDelete