Loop MboSet and output Mbo content

A very common programming pattern is to loop on a MboSet and read information from the included Mbo’s. This example can be technical combined with the RMI introduction to get a quick result since it requires a valid session object.

In this example I would like to show how to loop on all existing workorders in the system. Later on we will see how to select specific records from a MboSet, but for now let’s start with all workorders in the system. The following pattern can be used to achieve that objective and print out the workorder numbers:

woset = session.getMboSet('WORKORDER')

for i in range(0,woset.count()):

    # get one Workorder Mbo
    wo = woset.getMbo(i)

    # Read out a value
    print "Workorder ",wo.getString("WONUM")

Some of the important commands in this example are:

  • woset = session.getMboSet(‘WORKORDER’) – method to get a MboSet and stores this in the variable woset – in that case based on the session object
  • woset.count() – returns the number of records in woset
  • woset.getMbo(i) – gets the Mbo with index i
  • wo.getString(“WONUM”) – returns the string from DB Field WONUM from the Workorder Object

As always in programming there are often different ways to achieve the same goal and so I would like to introduce a different way on how it is possible to loop on a MboSet:

woset = session.getMboSet('WORKORDER')
wo = woset.moveFirst()

while (wo):
    # Read out a value
    print "Workorder ",wo.getString("WONUM")

    # get one Workorder
    wo = woset.moveNext()

In that case we use the methods of the MboSet object to navigate around using some simple commands:

  • wo = woset.moveFirst() – gets the first record from the woset
  • woset.moveNext() – moves the pointer to the next record in woset
  • while (wo != None) – loops as long as wo has a valid record (not at the end)


  • Can you please tell me how do I call the MBO helper methods? e.g. Asset.isRotating etc?

    • Hi Vivek,

      these methods can be called in normal Jython style…

      assetMbo = mbo # @UndefinedVariable

      if assetMbo.isRotating():
      # Rotating Asset founds

  • Admiring the persistence you put into your site and in depth information you present. It’s great to come across a blog every once in a while that isn’t the same out of date rehashed material. Excellent read! I’ve saved your site and I’m adding your RSS feeds to my Google account.

Leave a Reply

Your email address will not be published.