Friday, November 22, 2024

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

No comments:

Post a Comment