The first step in programming Maximo is working with the Maximo Business Objects (MBOs). In this lesson, we will cover the basics of working with this class files
Although there are class files for different MBO in Maximo (one for Asset, WorkOrder, etc.), these all extend the same base object. This means you can use this based object to do 90% of what you need to do. When access an MBO, you first use what is called and MBO Set object. The main class you will use is called “MboSetRemote”. You get an MBO set object by using the MXServer object.
The above line of code creates an MBO Set object of the ASSET MBO. Of course at this point you have all of the records in the Asset table. You will most like want to narrow this down. To do this you use the .setWhere method on the MboSetRemote object. For example if we wanted just one asset, we could use something like this:
In the above line of code, our MboSet object would return just one record (assuming that asset/siteid existed). Now one note about the setWhere method. You can use it over and over on the same MboSet object (like in a loop), but you must call the .reset() method after each setWhere or the subsequent calls to setWhere will do nothing.
Now that we have our collection of records we want to work with, we now need to get each record. We do this by using the getMbo() method. Of course you need make sure you have any records to process and we can do that with the .count() method. This will return how many records match your “setWhere”.
Just like how all MBO Set objects extend the same object, so do each of the record objects. They extend the MboRemote object. Again, you can do 90% of what you need to do.
As for setting data, there is one main method,that is just very overloaded.
If you want to delete a record, you can call the delete() method on the Mbo object.
Once you are done adding and updating and deleting records, you need to save your changes. All of your adding, updating and deleting have not made it to the database yet. This is done by calling the save() method on the MboSet object.
Now there is just one more thing we are going to cover and that is accessing child records. Maximo is a true Object Oriented database and from one MBO, you can access the children record in another MBO. This is done by using relationships. These relationships are defined in the Database Configuration app. to get the children MboSet object, you use the getMboSet() method on the Mbo Object.
Now what we have covered should get you through the most of what you have to do when MBOs. Now there are some methods that are unique to certain MBOs. The most common of these methods is to change the status. To call this, you will have to cast your MboRemote object to the actual object and then you can call the specific method.
Although there are class files for different MBO in Maximo (one for Asset, WorkOrder, etc.), these all extend the same base object. This means you can use this based object to do 90% of what you need to do. When access an MBO, you first use what is called and MBO Set object. The main class you will use is called “MboSetRemote”. You get an MBO set object by using the MXServer object.
psdi.mbo.MboSetRemote myAssetSet = psdi.server.MXServer.getMXServer().getMboSet(“ASSET”, getUserInfo())
myAssetSet.setWhere(“ASSETNUM = ’12345′ and SITEID = ‘EAGLEA’”);
Now that we have our collection of records we want to work with, we now need to get each record. We do this by using the getMbo() method. Of course you need make sure you have any records to process and we can do that with the .count() method. This will return how many records match your “setWhere”.
Just like how all MBO Set objects extend the same object, so do each of the record objects. They extend the MboRemote object. Again, you can do 90% of what you need to do.
if (myAssetSet.count() > 0)
{
for (int i=0; i < myAssetSet.count(); i++) {
psdi.mbo.MboRemote currentAsset = myAssetSet.getMbo(i);
}
}
The above code is great for accessing existing records, but what if you wanted to add a new record. well the MboSetRemote object provides an add() method. The best part of using the add() method is that it call all the Maximo functionality for you, just like you clicked “New” on the screen. {
for (int i=0; i < myAssetSet.count(); i++) {
psdi.mbo.MboRemote currentAsset = myAssetSet.getMbo(i);
}
}
MboRemote newAsset = myAssetSet.add();
Now the main things you will do with any record is retrieve and set data on the record. The MboRemote object provides lots of methods for this, depending on the data type. For retrieving data, they include (but not limited to): - getString()
- getBoolean()
- getDate()
- getDouble()
- getFloat()
- getInt()
As for setting data, there is one main method,that is just very overloaded.
- setValue()
if (currentAsset.getDouble(“PURCHASEPRICE”) < currentAsset.getDouble(“YTDCOST”)) {
currentAsset.setValue(“DESCRIPTION”,”Time to sell this thing.”);
}
The above code checks to see if the YTDCost has exceeded the Purchase Price and if so, it sets the description of the asset. (OK, this is not a particularly useful example but it does show you how to read and write attributes on an Mbo.) currentAsset.setValue(“DESCRIPTION”,”Time to sell this thing.”);
}
If you want to delete a record, you can call the delete() method on the Mbo object.
currentAsset.delete();
This method marks the record as to be deleted. Now you need to be very careful about deleting records in Maximo. Many are use in foreign key records. When this happens, Maximo will throw an exception when you try to delete the record. Also, with many objects (like Assets) you just don’t delete a recod, you just change the status of the object. Once you are done adding and updating and deleting records, you need to save your changes. All of your adding, updating and deleting have not made it to the database yet. This is done by calling the save() method on the MboSet object.
myAssetSet.save();
You HAVE TO call the save() method in order to have your changes make it to the database. Now there is just one more thing we are going to cover and that is accessing child records. Maximo is a true Object Oriented database and from one MBO, you can access the children record in another MBO. This is done by using relationships. These relationships are defined in the Database Configuration app. to get the children MboSet object, you use the getMboSet() method on the Mbo Object.
psdi.mbo.MboSetRemote
myAssetSpecSet = currentAsset.getMboSet(“ASSETSPEC”);
The parameter is the name of the relationship. Now you have an MboSet object and can manipulate it just as you can with any MboSet (even get children records for the children records).Now what we have covered should get you through the most of what you have to do when MBOs. Now there are some methods that are unique to certain MBOs. The most common of these methods is to change the status. To call this, you will have to cast your MboRemote object to the actual object and then you can call the specific method.
Cool, and where are enother lessons from this serie?
ReplyDelete