June 4, 2012

Sample Action Class

This entry is part of the Maximo Java Development series.

Sometimes you have to implement some complex logic in workflows or escalation and you feel limited by the out-of-the-box Maximo actions. In these cases you can unleash the Java power and code your algorithm in a custom action class.
In order to create a custom action class, you must extend the  psdi.common.action.ActionCustomClass class.

package cust.actions;

import java.rmi.RemoteException;
import psdi.common.action.ActionCustomClass;
import psdi.mbo.MboRemote;
import psdi.util.MXException;

public class SampleAction implements ActionCustomClass
{
  public SampleAction()
  {
    super();
  }

  public void applyCustomAction(MboRemote mbo, Object[] params)
      throws MXException, RemoteException
  {
    // Write custom code here
  }
}

As usual... compile, rebuild EAR and redeploy. For a full example of a custom action class look here.

To call this action from a workflow or escalation you have to register the new Maximo action. Go in System Configuration - Platform Configuration - Actions and create a new action. Choose Custom Class as Type, select the object for which the custom applies and provide the full class name (cust.actions.SampleAction) in the value field. Here is how the new Action should look.


8 comments:

  1. Could you provide some additional details on how you would extend ActionCustomClass to move data from the base object to another object. I would like to have workflow invoke a custom action that copies data from one object to another and I am not sure how to tackle this objective.

    ReplyDelete
    Replies
    1. In the applyCustomAction you have a reference to the Mbo. Use relationships to navigate MBOs and update data accordingly.
      For example, if you want to set all the description of the child POLINES of a PO do something like this.

      String desc = mbo.getString("DESCRIPTION");
      MboSetRemote polines = mbo.getMboSet("POLINES");
      for(MboRemote poline=polines.moveFirst(); poline!=null; poline=polines.moveNext())
      {
      poline.setValue("DESCRIPTION", desc);
      }

      Delete
  2. Thanks for the quick Response Bruno, Is there a way to output the contents of the string polines in the systemOut.log? I have done customizations using the integration root logger, but I am not sure how this is done when developing custom actions. Also, POLINES is the name of the relationship that is used to map PO to POLINE correct?

    ReplyDelete
    Replies
    1. You can use whatever logger you want.
      Yes POLINES is the name of the relationship from PO object to POLINES as defined in the Database Configuration.

      Delete
  3. hi, can u explain how can we take custom class parameters? there are 2 parameter in this class(mboremote and object). i want to take object parameter. thank you

    ReplyDelete
  4. My applyCustomAction function gets called repeatedly after performing operation in first iteration.
    But continues to get called, Why it is so ? Can you help ?

    ReplyDelete
  5. Could you provide some additional details on how you would extend ActionCustomClass to perform select action method for application.

    e.g. I want to create Investigation from Incident using Action.
    and for this standard Application Action has not supported the action.
    How can I achieve this using custom class in action ?

    ReplyDelete
  6. which status i can do action using custom class

    ReplyDelete