October 26, 2012

Reset the value of a field when another field is modified

This entry is part of the Maximo Java Development series.

Today I want to share with you some Java sample code to reset the value of a field when another field is modified.
In the example below I have implemented a little piece of logic to reset the WORKORDER.SUPEVISOR field when the WORKORDER.OWNERGROUP is modified.


Here is the Java code.

package cust.psdi.app.workorder;

import psdi.mbo.*;
import psdi.util.*;
import java.rmi.*;

/**
 * Custom field class to reset the supervisor when the Owner Group is changed
 */
public class FldWOOwnerGroup extends psdi.app.workorder.FldWOOwnerGroup
{
  public FldWOOwnerGroup(MboValue mbv) throws MXException
  {
    super(mbv);  
  }

  public void action() throws MXException, RemoteException
  {
    if (!getMboValue().isNull() &&
        !getMboValue().equals(getMboValue().getPreviousValue()))
    {
      getMboValue("SUPERVISOR").setValueNull(NOACCESSCHECK|NOVALIDATION_AND_NOACTION);
    }

    super.action();
  }
}

Deploy the FldWOOwnerGroup.class file in your Maximo source tree and attach it on WORKORDER.OWNERGROUP field using the Database Configuration application.

12 comments:

  1. I didn't think you could name the extending class the same as the superclass. Thanks for sharing.

    ReplyDelete
    Replies
    1. Sure you can.
      That's my personal best practice. I like to use the same name as the superclass and the same package name with a 'cust' prefix.

      Delete
    2. I would rather suggest to use a prefix before class name ex: "CustomFldWOOwnerGroup", this is the same strategy ISs use.

      Delete
  2. Hi there, do you know how do do this using automation script?

    ReplyDelete
  3. Bruno, thanks for your posts on MAXIMO customisation and Development. They are very useful for me as a beginner. Same as DuleyFacts, I would like to know how we can do that using automation script?

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Automation script.
      1) Create attribute launchpoint on attribute WORKORDER.OWNERGROUP.
      2) Add an OUT variable:
      supervisor
      3) assign to it the value:
      supervisor
      4) Jython script will be look like this:
      if ownergroup != None & ownergroup != '':
        supervisor=None

      Automation script will not start, while you not CHANGE the value of the OWNERGROUP field,
      so we don't need to check the previous value

      Delete
  4. This comment has been removed by the author.

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

    ReplyDelete