1

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"))
max092012
  • 365
  • 1
  • 5
  • 25
  • So, you are starting on the non-persistent record (mbo) and you leave it for whatever record this one was related from (getOwner) and then you go from that other MBO to a new set of CXDEMO records (that themselves may or may not be non-persistent)? Is this really what you intended? – Dex Dec 04 '19 at 01:55
  • @Dex Owner here is WORKORDER and CXDEMO is Persistent. I basically need to show the data present in CXDEMO in the dialog using non-persistent object CXTEST – max092012 Dec 04 '19 at 01:59
  • You can't just use the CXDEMO object as the backing object on the dialog? If you are copying all of the CXDEMO data into CXTEST, it would seem better to cut out the middle man and just use CXDEMO. Also, your variable name is a misnomer then, because you are storing the CXDEMO set in "npSet", which you just said is _not_ non-persistent. – Dex Dec 04 '19 at 02:03
  • @Dex CXDEMO is persistent and CXTEST is non persistent. I have used non persistent because the value selected in the dialog does not sets the owner mbo hence used non persistent object. – max092012 Dec 04 '19 at 02:14
  • 1
    That's a flaw of the way you are setting up and configuring your lookup (did you ever do that maxlookupmap entry we talked about? You didn't address that, for instance. Also, I don't think you can use a standard dialog and expect it to work as a lookup, Maximo has special dialogs for that, which you stopped using), not because you are using a persistent versus non-persistent MBO. In fact, switching this to a non-persistent MBO just makes everything needlessly complicated. – Dex Dec 04 '19 at 02:24
  • @max092012 Have a look at this document. It contains very good guidelines for mbo programming: https://www.ibm.com/developerworks/community/wikis/home?lang=en#!/wiki/IBM%20Maximo%20Asset%20Management/page/Maximo%20business%20object%20development – JPTremblay Dec 04 '19 at 14:37

1 Answers1

2

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.

Dex
  • 1,241
  • 6
  • 13