Custom Java Action Class Example

This entry is part of the Maximo Java Development series.

In a previous post I have described how create a custom action class using Java.

Here is a full example that can help to understand how to navigate objects and set values.

package cust.psdi.app.workorder;

import java.rmi.RemoteException;

import psdi.common.action.ActionCustomClass;
import psdi.mbo.MboConstants;
import psdi.mbo.MboRemote;
import psdi.mbo.MboSetRemote;
import psdi.util.MXException;

/**
* Sets the Workorder description with a new one obtained concatenating the
* following related descriptions:
* - :JOBPLAN.DESCRIPTION
* - :PM.LOCATIONS.DESCRIPTION
* - :PM.ASSET.DESCRIPTION
*
* @author Bruno Portaluri
*/
public class ActionSetDescriptionFromPm implements ActionCustomClass
{
public ActionSetDescriptionFromPm()
{
super();
}

public void applyCustomAction(MboRemote mbo, Object[] params) throws MXException, RemoteException
{
String desc = "";

// Get the description of the Job Plan
MboSetRemote jp = mbo.getMboSet("WO_JOBPLAN");
if (jp.getMbo(0)!=null)
{
desc = desc + jp.getMbo(0).getString("DESCRIPTION");
}


// Get the description of the Job Plan
MboSetRemote pm = mbo.getMboSet("WO_PM");

if (pm.getMbo(0)!=null)
{
// Get the description of the PM's Location
MboSetRemote locations = pm.getMbo(0).getMboSet("LOCATIONS");
if (locations.getMbo(0)!=null)
{
desc = desc + " - " + locations.getMbo(0).getString("DESCRIPTION");
}

// Get the description of the PM's Asset
MboSetRemote asset = pm.getMbo(0).getMboSet("ASSET");
if (asset.getMbo(0)!=null)
{
desc = desc + " - " + asset.getMbo(0).getString("DESCRIPTION");
}
}

// Truncates to fit the field length
desc = desc.substring (0, 100);

System.out.println("Setting WO's " + mbo.getString("WONUM") + " description:" + desc);

mbo.setValue("DESCRIPTION", desc, MboConstants.NOACCESSCHECK|MboConstants.NOVALIDATION_AND_NOACTION);
}
}
Custom Java Action Class Example

2 thoughts on “Custom Java Action Class Example

  1. Very good example.

    I would replace if (xxx.getMbo(0) != null) for if (!xxx.isEmpty()), it is clearer to understand and that makes the source code a little more legible. I know it is not exactly the same, but for practical purposes these two "ways" can be used interchangeably.

    Also, I tend to use variable names ending with "set" when working with MboSets. Another alternative is using "plural" for sets and "singular" for Mbos when naming variables. Typically these differences come handy when you want to iterate a set and assign the "current" Mbo inside the loop to a local variable.

    I do tend to think these conventions also make the code a little more easy to understand (even by yourself in the future) πŸ˜‰

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top