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.
Quering and fetching MBOs

11 thoughts on “Quering and fetching MBOs

  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.

  2. 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

  3. 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

  4. 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();

  5. 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.

  6. 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!

  7. 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…

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

  9. Hello, Bruno!
    Can you help me?
    There is no information about how to create mbo in Automation Script. Can you say how to do this?

  10. Hi, anyone knows how can I set sql select fields to MboRemoteSet ? My goal is to run a single query to fetch description of all records.

Leave a Reply

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

Scroll to top