Friday, November 22, 2024

Maximo Automation Script Performance Tip: Avoid using setQbe and setWhere

 

When accessing an MboSet, it is common to need to find a particular record. There are two primary methods for this. The first is call Query By Example (setQbe). The second is the Where clause (setWhere).

Let’s do an example. Say we need to find the Asset with the assetnum = ‘1000’. (We assume there is only one site in this example.) Here is a sample using the Query By Example:

    assetMboSet = session.getMboSet("ASSET")
    assetMboSet.setQbe("ASSETNUM", "1000")

This would work but it has consequences. First, this would return all assets that have ‘1000’ in the assetnum. The bigger consequence (at least for performance sake), is what Maximo does in the background. QBE translates to this SQL:

    SELECT * FROM ASSET WHERE ASSETNUM like ‘%1000%’

If you are truly looking for all assets that have ‘1000’ within their assetnums, then this the right approach, but if you only was the asset with the assetnum ‘1000’, this is a slow approach as Maximo will do a full scan to find all the records.

The second approach is to use the Where clause. Let’s look at the same example but using the setWhere method:

    assetMboSet = session.getMboSet("ASSET")
    assetMboSet.setWhere("ASSETNUM = '1000'")
    

This approach will return just the asset you are looking for. This approach would translate to this:

    SELECT * FROM ASSET WHERE ASSETNUM = '1000'

The setWhere method basically gives you the ability to add a SQL ‘Where’ clause to the MboSet. In reference to performance, the ‘like’ method is slower as database has to look at the data in the ASSETNUM column to see if it contains the 1000 value, whereas the ‘=’ method just checks to see if the entire content of ASSETNUM matches.

Unless you need to perform a ‘LIKE’ method, you should always use the setWhere method as it will be faster. And, if you really need to use a ‘LIKE’ query, you can always use: setWhere("ASSETNUM like ‘%1000%’”), as it would do the same thing as setQbe does. 

Now that I have shown that setWhere is better than setQbe, there is another and even better way to do this. That is to us a dynamic relationship. As you have seen, getMboSet method is passed the name of the MBO that you want to access. However, there is an overloaded version of this method that allows you to create a dynamic relationship. Using this, you can pass the condition as part of the relationship. This will allow the database to do the filtering instead of Maximo. The new code would look like this:

    assetMboSet = session.getMboSet("$tempAsset","ASSET","ASSETNUM='1000'")
 

The first parameter is a temporary name for the relationship. Make sure it starts with a dollar sign. Next is the name of the MBO and the last parameter is the where clause (without the word 'WHERE').  This method has the smallest impact on Maximo's overhead.

Happy Coding

Using Discardable MboSets in Maximo Automation Scripts

 

I would say about 90 percent of the time that, in Maximo code, when we access an MBO set, we just navigate through it, first record to last. Usually it is to retrieve a certain value for calculation or some other reason. This is a sample of what that code looks like:

    assetMboSet = mbo.getMboSet("ASSET")

    curMbo = mbo.moveFirst()
    while curMbo != None:
        # Read some value from the mbo
        curMbo = mbo.moveNext()

This is pretty straight forward code but let’s look at the impact of this code in reference to performance. Whenever you access an MboSet, Maximo automatically caches the data as it assumes that you will probably want edit it. However, if you only just want to read through a MboSet, then placing the data in cache means it is taking up memory space that you do not need to take up. A better approach for MboSets that you plan on just reading through (no updates), is to make the MboSet “Discardable.” This tells Maximo to not place the data in the cache, freeing up memory. The code to do this is:

    assetMboSet = mbo.getMboSet("ASSET")
    assetMboSet.setFlag(MboConstants.DISCARDABLE, true)
    curMbo = mbo.moveFirst()
    while curMbo != None:
        # Read some value from the mbo
        curMbo = mbo.moveNext()

As you can see it only take one line of code but can have a big impact on memory usage. One important thing to note is that a “Discardable” MboSet is always read-only. If you are struggling with JVM memory availability in your Maximo environment, this is an easy way to help free up some of it.

Happy Coding

Maximo Automation Script Debugging

 

Maximo automation script debugging

Someone once told me that “All developers would write 100% bug free code if it wasn’t for users.” Sadly for us developers, we live in a world full of users. That means we have to debug our code. One of the biggest challenges facing a Maximo developer is often trying to debug automation scripts. When you have multiple scripts that are all being trigger, trying to figure out which script is causing the system to be slow is a major problem.

This article is going to talk about two parts of debugging scripts. The first is how to make your life easier in the future by adding log statements to your scripts. The second is how to use logging to figure out what Maximo is doing and all the scripts that are running.

 Debugging your code:

The one thing that you should have in every automation script is some logging statements. They not only allow you do debug code in a production environment (by changing the debug level), but also is a great way to comment and document your code. Maximo has several loggers that you can use but since there is one for automation scripts, that would be a good choice. Here is an example of how to create a logger variable and how to write to it:

    from psdi.util.logging import MXLoggerFactory

    logger = MXLoggerFactory.getLogger("autoscript")

    logger.info("Entering SR_INIT script for ticket " + mbo.getString("TICKETID"))
    logger.debug("This is a debug message")
 

The most common log methods are: .error(), .warn(), .info() and .debug(). (There are other methods but these are the main/most commonly used.) These correspond to the Log Levels that you can select in the logging application in Maximo. Now you might feel like you should remove all the .debug() statements once your code is tested and working but you should not. Leaving them in will help in the future should some have to debug your code.

Figuring out what Maximo is doing:

Trying to figure out what Maximo is doing with automation script can be a struggle, especially if your environment has a lot of automation scripts. It turns out that the autoscript log can help a lot when you change the log level for it. Of course, anytime you turn up the volume of log entries, you run into a problem with the log file filling up to quickly. As such, I recommend you, for the purposes of debugging, having the autoscript log write to its own file. You don’t have to but if you don’t and have a lot of debugging data being written to the log, then it can be hard to determine what is from the autoscript and what isn’t. Here is how you do that:

Access the Logging application and then from the Actions menu, select Manage Appenders.

Then click New row.

·       Appender: Give it a name.

·       Description: Enter a description

·       Append Implementation Class: psdi.util.logging.MXFileAppender

·       File Name: This will be the name of the log file. Be sure to end it with “.log”

Save

No alt text provided for this image

Now edit the root logger: autoscript. On appenders, select your new appender (click the icon next to the field).

Also change the log level to INFO or DEBUG.

Be sure to perform “Apply Settings”.

No alt text provided for this image

Now Maximo will write everything from the autoscript log into your new file, making it easier for you to read it. But what information does “INFO” and “DEBUG” give you?  INFO will tell you the name of each script that runs, including the launchpoint name, user, Mbo and execution time. DEBUG will also include the name of each variable in that script that was created and all the listeners.

Example of setting ‘autoscript’ logging to DEBUG:

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ScriptMboEventListener eventValidate

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ASSETScriptMboEventListener eventValidate called.

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ScriptMboEventListener eventValidate

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ASSETScriptMboEventListener eventValidate called.

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ScriptMboEventListener eventValidate

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ASSETScriptMboEventListener eventValidate called.

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ASSETScriptMboEventListener eventAction called. for script Z_DEFAULTNAME launch point Z_DEFAULTNAME

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ASSETScriptMboEventListener eventAction called. for script USERINPUT launch point USERINPUTE2

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-UIASYNC-5167] ASSETScriptMboEventListener eventAction called. for script TEST-JDBC launch point TEST-JDBC

17 Apr 2020 13:08:11:121 [INFO] [MXServer] [CID-MXSCRIPT-5168] Correlation started.

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] about to execute the cached compiled script for TEST-JDBC for launch point TEST-JDBC

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting app value ASSET

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting mboname value ASSET

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting service value com.ibm.tivoli.maximo.script.ScriptService@23de5242

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting interactive value true

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting onupdate value false

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting scriptName value TEST-JDBC

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting mbo value psdi.plust.app.asset.PlusTAsset@27e1c2e1

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting ondelete value false

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting user value WILSON

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting onadd value false

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting launchPoint value TEST-JDBC

17 Apr 2020 13:08:11:121 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] created script context for cached compiled script TEST-JDBC for launch point TEST-JDBC

17 Apr 2020 13:08:11:122 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting MXServer value <type 'psdi.server.MXServer'>

17 Apr 2020 13:08:11:122 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting ConnectionKey value <type 'psdi.security.ConnectionKey'>

17 Apr 2020 13:08:11:123 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting DBShortcut value <type 'psdi.mbo.DBShortcut'>

17 Apr 2020 13:08:11:123 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting Connection value <type 'java.sql.Connection'>

17 Apr 2020 13:08:11:123 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting MXServer

17 Apr 2020 13:08:11:123 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting mxServer value psdi.server.MXServer@79db0e30

17 Apr 2020 13:08:11:123 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting mxServer

17 Apr 2020 13:08:11:124 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting conKey value psdi.security.ConnectionKey@7793b66a

17 Apr 2020 13:08:11:124 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting DBShortcut

17 Apr 2020 13:08:11:124 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting dbs value psdi.mbo.DBShortcut@2cca736

17 Apr 2020 13:08:11:124 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting dbs

17 Apr 2020 13:08:11:124 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting conKey

17 Apr 2020 13:08:11:124 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting c value 0

17 Apr 2020 13:08:11:124 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting dbs

17 Apr 2020 13:08:11:140 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting rs value oracle.jdbc.driver.ForwardOnlyResultSet@4752903d

17 Apr 2020 13:08:11:144 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting rs

17 Apr 2020 13:08:11:144 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting rs

17 Apr 2020 13:08:11:150 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting c value 686

17 Apr 2020 13:08:11:150 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting rs

17 Apr 2020 13:08:11:150 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting rs

17 Apr 2020 13:08:11:150 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting dbs

17 Apr 2020 13:08:11:152 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting dbs

17 Apr 2020 13:08:11:153 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting errorgroup value configure

17 Apr 2020 13:08:11:153 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting errorkey value BlankMsg

17 Apr 2020 13:08:11:153 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] getting c

17 Apr 2020 13:08:11:153 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] putting params value ['record count: 686']

17 Apr 2020 13:08:11:153 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] execution completed for cached compiled script TEST-JDBC for launch point TEST-JDBC

17 Apr 2020 13:08:11:153 [DEBUG] [MXServer] [CID-MXSCRIPT-5168] The total time taken to execute the TEST-JDBC script for the TEST-JDBC launch point is +32 ms.

17 Apr 2020 13:08:11:153 [INFO] [MXServer] [CID-MXSCRIPT-5168] Correlated data: BEGIN LaunchPoint:TEST-JDBC app:ASSET Script:TEST-JDBC UserName:WILSON MboName:ASSET MboId:204 ElapsedTime:32 ms  END
 

I hope this helps with your debugging tasks. 

Happy Coding

How to Retrieve a JDBC connection in Automation Scripts

 

There are times in automation scripting that you need a JDBC connection to directly access Maximo database in order to perform some job. This is not common since all Maximo data can be accessed through standard MboSets. However, you may need to access non-Maximo tables, perform specific SQL statements or bypass Mbos for performance reasons. The two main approaches to issue standard SQL code through JDBC are described here.

Of course, you could do the standard application approach where you get the connection string, username and password and then open a connection yourself. However, the Maximo Server object can give us the connect object. This eliminates the need to have the username and password stored somewhere (security audits like that). As such I will not be covering that approach here. In both examples, we will be using the Maximo Server Object (MXServer) to get the database connection.

JDBC Connection

Here is a sample that shows how to get a JDBC connection from Maximo connection pool (and correctly release it).

    from psdi.server import MXServer
    from psdi.security import ConnectionKey
    from java.sql import Connection
    from java.sql import Statement
    
    mxServer = MXServer.getMXServer()
    conKey = mxServer.getSystemUserInfo().getConnectionKey()
    con = mxServer.getDBManager().getConnection(conKey)

    c = 0
    try:
        stmt = con.createStatement()
        rs = stmt.executeQuery("select count(1) from asset")
        while rs.next():
            c = rs.getInt(1)
        rs.close()
        stmt.close()
        con.commit()
    except:
        #error do something meaningful about the error
        c = -1
    finally:
        mxServer.getDBManager().freeConnection(conKey)


If you have done any java JDBC programming at all you will see that this is a pretty standard approach. We first get the credentials for connecting to the database (conKey). Then we use it to get a connection object (con) from the Maximo database connection pool. Then we use a Statement object (stmt) to get a ResultSet object (rs). We then process that ResultSet. Take special note of the last line:

              mxServer.getDBManager().freeConnection(conKey)

This is how you tell Maximo that you are done with the JDBC connection so it can free it to the connect pool. Eventually the garbage collection would see that your script is complete and free the connection, but issuing the command makes it happen immediately, lessoning the change of running out of available connections. (e.g. when you are processing thousands of records, so the script is running thousands of times.)

DBShortcut class

A quick easy way to get a java.sql.ResultSet object is to use DBShortcut class. This object comes in the psdi.mbo package and is designed to quickly retrieve result-sets or run update statements against the database.

    from psdi.server import MXServer
    from psdi.security import ConnectionKey
    from psdi.mbo import DBShortcut
    from java.sql import Connection

    mxServer = MXServer.getMXServer()
    conKey = mxServer.getSystemUserInfo().getConnectionKey()
    dbs = DBShortcut()
    dbs.connect(conKey)

    c = 0
    try:
        rs = dbs.executeQuery("select count(1) from asset")
        while rs.next():
            c = rs.getInt(1)
        rs.close()
        dbs.commit()
    except:
        #error do something meaningful about the error
        c = -1
    finally:
        dbs.close()


The big difference here is that by using the DBShortcut class, Maximo controls all of the required connection objects (e.g. Connection, Statement) so you do not have to worry about them. It just gives you a ResultSet. Where this really is shown is in the cleanup. We don’t have a Statement object to close, instead of committing the connection, we tell DBShortcut to commit(), and by simply calling the close() method on the DBShortcut variable, it will automatically free up the connection. The DBShortcut is doing everything we did in the JDBC Connection example, it just does it for you so you can use few lines of code.

Happy Coding

The best way to process an mboSet in Maximo Automation Script

 

As with all things programming, there is more than one way to do things, including processing an MboSet of records. As it turns out, some ways are better (faster) than others. This is probably the most common approach (especially for new developers).

    mboSet = mbo.getMboSet("Asset")
    for i in range (0, mboSet.count()):
        curMbo = mboSet.getMbo(i)
        ...

This will process the ASSET MboSet just fine, however, each time the loop compares i with the top value in the range (mboSet.count()), the code will recount how many records are in the in mboSet variable. So if you have 100,000 thousand records in the ASSET table, then the count will be run 100,000 times. The more records in the MboSet, the worse the performance is. Now, granted you could do something like this:

    mboSet = mbo.getMboSet("Asset")
    recordCount = mboSet.count()
    for i in range (0, recordCount):
        curMbo = mboSet.getMbo(i)
        ...

This would only perform the count only once and would improve performance. However, there is a way you can process the mboSet without even performing the mboSet.count():

    mboSet = mbo.getMboSet("ASSET")
    curMbo = mboSet.moveFirst()
    while curMbo:
        ...
        curMbo = mboSet.moveNext()

This will process each record in the record set but since we don't call .count() at all, the performance is better. The Count() method is a costly one (performance wise) and its use should be minimal. In the world of Maximo automation scripting, performance can quickly become a big issue, so every little bit will help.

Happy coding

User Input in Maximo Automation Scripts

 

In Maximo, it appears that there is no way to get user input from a user in an Automation Script. Automation scripts are great at doing back group tasks and things that do not require addition user input. However, it turns out that you can get user input in an automation script (although it is a bit cumbersome and limited in its functionality.) You cannot have the user type in text that you need (if you need this kind of input, then create a dialog box), but you can get some input based on button selection.

This code was taken from java class development and adapted to automation script, so if you want to do this in a java class, then you can.

This code is not perfect as it will appear as an error when they save and then they will be able to make the select that will allow your script to finish.

The user input options are based on the buttons that are available to the MsgBox. They are: OK, Close, Cancel, Yes, and No.

In this example, we are going to trigger off the Asset Priority field and if the user entered a priority of 1, then we will ask them if they want to send an email. Let’s get geeky.

Steps:

1.    In the Database Configuration application, select the Messages action and create a new message with the following values:

    Message Group: XXXXX
    Message Key: yyyyy
    Display method: MSGBOX
    Message ID Prefix: BMXZZ
    Message ID Suffix: I
    Display id: 1
    Value: Asset custodian can be notified through email when priority {0} is set. Send email?
    Button Selection: Check Yes and No Buttons

2.    Go to Automation Scripts application, create a script with an attribute launch point to run the Attribute Launch Point.

3.    Specify the launch point name, and select the ASSET object and the PRIORITY attribute.

4.    In the Events section, choose the Run Action radio button.

5.    Specify the script name.

6.    Paste the following source code and then click Create.

    from psdi.util.logging import MXLoggerFactory

    logger = MXLoggerFactory.getLogger("maximo.script")

    # logic implementation if user selects Yes choice (clicks Yes button)
    def yes ():
      logger.error("you clicked yes")

    # logic implementation if user selects No choice (clicks No button)
    def no ():
      logger.error("you clicked no")


    # logic to present the choice message initially
    def dflt ():
      params=[""]
      logger.error("Throw ERROR")
      # Use the service utility's yncerror() method to push the choice message
      service.yncerror("demo", "userinput",params);

    # Declare the user input choices and the corresponding functions implemented in this script
    cases = {service.YNC_NULL:dflt, service.YNC_YES:yes, service.YNC_NO:no}

    # Make sure the choice message is presented only
    # if the field validation was triggered from user interface
    if interactive:
       if priority < 2:
         logger.error ("About to do something")
         # Use the service utility's yncuserinput() method to trigger the entire interaction
         # User's response is stored in a local variable x
         x = service.yncuserinput()
         logger.error("User input: "+str(x))
         # Process the user input using Jython's case statement
         cases[x]()

 

Now go into assets and change the priority of an asset to. Now save. You should receive a message about errors. Click on the error, click Yes or No and you script will process accordingly.

If you are wondering how this code works, what happens is when the user is presented with the message box, your script is actually done executing. When a users clicks on one of the buttons, the script is called again. Keep this in mind as your code as your code will be executed twice.

This is a nice piece of code to have in your tool box but probably not one you will use much.

Happy Coding

Understanding Zombies in Maximo Development

 

No, this is not a diatribe on survival techniques in a hypothetical post apocalyptic world. We will be talking about real zombies. In Maximo zombies do exists. Chances are, if you have done any coding in Maximo, you have created a zombie but never had to deal with it as once you created it, because you were done processing and you let garbage collection clean up your zombie.

The first thing we need to do is define what a zombie is (for those that don't know). All Maximo Mbos are part of a transaction. That means that once you are done making your changes and execute the save() method, your changes are written to the database. Since the save() command will update the database, the Mbo is considered to a "Live" Mbo. An Mbo becomes a Zombie when it loses that transaction. The Mbo will still function and act like a live Mbo (all field classes, autoscripts, etc will still function), but when you call the save() method, nothing happens. The data is NOT written to the database and you do NOT get an error. In your code it will look like everything processed correctly but your data did not get updated to the database. So how does an Mbo lose its transaction (aka, become a zombie)? It turns out that when you call the save() method, Maximo closes the transaction that the Mbo was part of. Since Maximo does NOT assign it a new transaction, the Mbo becomes disconnected from the database. It becomes a Zombie data record.

Let's look at an example. Here we assume we have a valid Asset Mbo and MboSet objects and we want to update the description:

     …  
     assetMbo.setValue("Description", "This is our new Truck.")  
     assetMboSet.save();  
     assetMbo.setValue("Description", "Now it is a car.");  
     assetMboSet.save();  
     String description = assetMbo.getString("Description");  
     … 

So what do you think the value of the Description will be in the database? The answer is "This is our new Truck.". However, the value of the variable "description" is "Now it is a car." The reason is that once the save() method was called, the assetMbo object became a zombie and although it still acts like live Mbo, it will not update the database. The object (assetMbo) has one value while the database has another. The worst part is that you did not receive an error or anything in your code to tell you that the save did not work.

There is no way to make the assetMbo a live Mbo once it has gone zombie. (Just like in real life, there is no cure for zombism.) Once a save is called, all Mbos that are part of the MboSet become zombies. That means if you ask the MboSet for an Mbo, it will be a zombie Mbo. You have to go back to the database and re-retrieve the record. Also, any child MboSet created from a zombie Mbo will have zombies Mbos.

Now in our example it is pretty easy to see that after the first save, the Mbo is a Zombie, but Maximo is pretty complex and someone else's code could be performing a save that you are not aware of. IBM does have a way to detect if an Mbo has gone zombie on you. You can call isZombie() method on the Mbo object.

     …  
     if assetMbo.isZombie():
       # how rude, someone zombified our Mbo  
       # now we have to either throw an error so someone can go find that save and remove it   
       # or go retrieve the record again.  
     …  

It is a simple check and, given good coding practices, will probably only be used for debugging. This check is ONLY available to the Mbo. There is no way to directly see if all Mbos on an MboSet have gone zombie. You would have to grab each Mbo from it and check to see if they are zombies.

So far we have talked about Zombie Mbos like they are a bad things but they have a good use too. Since they act just like a live Mbo but can never update the database, they are great for passing to class files that should never be updating the record anyway. One example I can think of would be a third party API that wants you to pass it an Mbo. Giving the API a Zombie will ensure that they cannot affect the data while providing them the full functionality of the Mbo. Basically any situation where you want to make sure the code can never update the database, a zombie is a good option.

So, how do you get a zombie Mbo? Well you could get the Mbo and then call save(), but I would not recommend this. This would cause the "changed by" field to be updated. As it turns out, IBM provides a method to get an Mbo from an MboSet as a Zombie. Here is an example:

     …  
     assetMboSet.moveFirst()  
     zombieMbo = assetMboSet.getZombie()
     …  

Now our Mbo is a zombie. Although it is a zombie, it is still a full MboRemote object and since we got it from asset, we can even cast it to an asset object Mbo (which will still be a zombie object). While assetMboSet object can still give out "live" Mbos, zombieMbo will only give out zombie Mbos. Sadly there is only one getZombie() method so you can't call getZombie(0) to get the first Mbo. Instead you have to use the MboSet "move" commands (moveNext(), movePrev(), moveFirst(), moveLast()) to move to the record you want and then call the getZombie() to get the record.

As you can see zombies are real. If you have called the MboSet.save() method, then you have created Zombies but since logically, the save() should be the very last thing you do, you have never had to deal with a zombie. Even so, it is important to be aware that they do exist and if, in your code, you see behavior where your updates are not making it into the database after you call save(), then you might be dealing with a Zombie. 

Happy Coding