max092012
max092012

Reputation: 407

Looping in non-persistent object using automation script in maximo

I would like to know how to perform looping using automation script on a non-persistent object using automation script in maximo. The script is written on the non-persistent object triggered during Initialize . This non-persistent object is mapped to a dialog in work order tracking application and should bring a list of records. There is no error however when the dialog is opened it brings only 1 record. Below is the python script,

npSet=mbo.getOwner().getMboSet("CXDEMO")
 if(npSet.count()>0):
    for i in range(0,npSet.count()):
        np = npSet.getMbo(i)
        mbo.setValue("WONUM",mbo.getOwner().getString("WONUM"))
        mbo.setValue("SITEID",mbo.getOwner().getString("SITEID"))
        mbo.setValue("CONTRACTNUM",np.getString("CONTRACTNUM"))
        mbo.setValue("VENDOR",np.getString("VENDOR"))

Upvotes: 1

Views: 1660

Answers (1)

Dex
Dex

Reputation: 1271

Your comments say you are looping through a persistent set and trying to copy the data back into your starting non-persistent set (not what you actually asked in the question). You would appear to be looping through the persistent set fine (more or less), but every loop is setting the data on the same MBO record (mbo). There is nothing happening here to make sure you move to or create a new record in the non-persistent set to put that data into, so instead, you are overwriting the same single non-persistent record in each iteration of the loop.

You can create a new record in your non-persistent set in the same way you do with a persistent set, by calling the .add() method. You can store the reference to your current non-persistent set for easier re-use later. You should also minimize your .count() calls, each one is a new query to the database which isn't good for performance. Your code would now look like this:

npSet = mbo.getThisMboSet()
woMbo = np.getOwner()
wonum = woMbo.getString("WONUM")
siteid = woMbo.getString("SITEID")
pSet = woMbo.getMboSet("CXDEMO")
pSize = npSet.count()

if (pSize > 0):
    for i in range(0, pSize):
        pMbo = pSet.getMbo(i)
        npMbo = npSet.add()

        npMbo.setValue("WONUM", wonum)
        npMbo.setValue("SITEID", siteid)
        npMbo.setValue("CONTRACTNUM", pMbo.getString("CONTRACTNUM"))
        npMbo.setValue("VENDOR", pMbo.getString("VENDOR"))

This will still leave you with an empty first record, since Maximo already added the original mbo and we didn't use it. You can add a check to your loop to say if i == 0, then set npMbo to the original mbo.

Upvotes: 2

Related Questions