November 17, 2012

Quering and fetching MBOs

This entry is part of the Maximo Java Development series.

To query a Maximo table using Java you need to perform the following steps:
  1. Get a reference to the MboSet.
  2. Specify a where clause.
  3. Loop through the MboSet and fetch Mbos.
The following example shows how to retrieve all the assets located in BEDFORD site.

MboSetRemote assetSet = getMboSet("ASSET");
assetSet.setWhere("LOCATION='BEDFORD'");
MboRemote asset=null;
for(int i=0; (asset=assetSet.getMbo(i))!=null; i++)
{
    ...
}

  • The getMboSet method gets a reference the ASSET table.
  • The setWhere method specifies the SQL where clause that must be applied to filter data. If the setWhere is not invoked, the entire table will be fetched.
  • The getMbo method returns a specific element of the MboSet collection. The first invocation of getMbo method automatically fetches data and initialize the MboSet.


10 comments:

  1. Just one question: Why don't you use the "best solution" without an "i" like said in your article "Best way to loop through an MboSet"? ;-)

    P.J.

    ReplyDelete
    Replies
    1. You are right, there is a more elegant solution to loop through an MboSet.
      However, in basic articles like this, I prefer to use this method that can be simpler for people who don't know Java very well.
      It seems you are reading my blog very well ;-)
      You are welcome.
      Bruno

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

      Delete
    3. i need a mbo customization.give me the best links iam lerner.....i dont know java please give me best articles,,,,,,,,

      Delete
  2. Hey Bruno...do you know the Code to get the current set based on the query that was entered on the search screen?

    I've tried getMboSet() but that just gives me all the records in the entire WORKORDER application. I'm doing this in a Bean Class

    ReplyDelete
    Replies
    1. If you are into an AppBean class you should be able to do something like that:
      DataBean databean = app.getDataBean();
      int currrow = databean.getCurrentRow();
      String where = databean.getAppWhere();

      Delete
  3. you should probably use Qbe (mySet.setQbe("ASSETNUM","1001") instead of hand-formatted whereClause.
    If you need more advanced whereClause, I suggest you to use SqlFormat object.

    ReplyDelete
  4. Hi Bruno,

    Is there anyway to limit the resultset returned when we do query with MboSetRemote? For instance I have an ASSET table with more than 50,000 records and I want to limit the number of results returned, eg records from row 5000 to 5500.

    MboSetRemote assetSet = getMboSet("ASSET");
    MboRemote asset = assetSet.getMbo(j);

    This will hit MXApplicationException fetchStop exception if j is too large (value). Thanks!

    ReplyDelete
  5. Hi Bruno
    I got problem this code:
    MboSetRemote assetMboSet = session.getMboSet("ASSET");
    and appear on Console:
    Exception in thread "main" psdi.util.MXSystemException: system#remoteexception
    at psdi.util.RMISession.getMboSet(RMISession.java:358)
    at com.maximodev.MxRemoteConnection.main(MxRemoteConnection.java:26)
    Caused by: java.rmi.UnmarshalException: error unmarshalling return; nested exception is:
    java.lang.ClassNotFoundException: psdi.plusg.app.asset.PlusGAssetSet_Stub (no security manager: RMI class loader disabled)
    at sun.rmi.server.UnicastRef.invoke(Unknown Source)
    at psdi.server.MXServer_Stub.getMboSet(Unknown Source)
    at psdi.util.RMISession.getMboSet(RMISession.java:350)
    What is mean the problem above and solve the problem?
    Thank you...

    ReplyDelete
  6. Hello Wakeel. I can see a ClassNotFoundException. Did you import the necessary package? i.e. import psdi.mbo.MboSetRemote

    ReplyDelete