Search code examples
xmlintegrationjythonmaximo

Maximo Automation Script for Integration


I really need help, I can't seem to find an answer to this. What I want to happen is during the inbound of data from the xml to the system, the PRNUM will be queried to the PRLINE object (which is the child object of the PR) so that I can get the CONTRACTNUM field, but I cant seem to get a value from it. I always get an error of Nonetype because its empty.

from psdi.server import MXServer
def beforeMboData(ctx):
    mbo = ctx.getMbo()
    struc = ctx.getData()
    prlineSet = MXServer.getMXServer().getMboSet('PRLINE', ctx.getUserInfo())
    prlineSet.setWhere("PRNUM = '"+struc.getCurrentData('PRNUM')+"'")
    prLine = prlineSet.moveFirst()
    contractSet = MXServer.getMXServer().getMboSet('CONTRACT', ctx.getUserInfo())
    contractSet.setWhere("CONTRACTNUM = '"+prLine.getString('CONTRACTNUM')+"'")
    contractRec = contractSet.moveFirst()
    struc.setCurrentData('CONTRACTID',contractRec.getInt('CONTRACTID'))

And the xml looks like this:

<max:PR action='AddChange'>
    <max:PRNUM>SMPL</max:PRNUM>
    <max:SITEID>BEDFORD</max:SITEID>
    <max:VENDOR>JOHNS</max:VENDOR>
    <max:PRLINE action='AddChange'>
        <max:PRLINENUM>1</max:PRLINENUM>
        <max:ITEMNUM>01231</max:ITEMNUM>
        <!-- I forgot the other fields here -->
        <max:CONTRACTNUM>X1C1</max:CONTRACTNUM>
        <max:CONTRACTID></max:CONTRACTID>
    </max:PRLINE>
</max:PR>

The CONTRACTID field is just for testing because I was trying to see if I will retrieve some data and I will remove it soon. I'm new to this and I also dont know how to get the ChildObject Data from to xml with the automation script to make it easier. I can't find anything on Google about something like this.


Solution

  • So after a lot of trial and errors here's what worked

    from psdi.server import MXServer
    def beforeCreateMboSet(ctx):
        mbo = ctx.getMbo()
        struc = ctx.getData()
        try:
            contractSet = MXServer.getMXServer().getMboSet('CONTRACT', ctx.getUserInfo())
            prLine = struc.getChildrenData('PRLINE')
            prCount = len(prLine)
            count = 0
            while count < prCount:
                struc.setAsCurrent(prLine,count)
                contractNum = struc.getCurrentData('CONTRACTNUM')
                contractSet.setWhere("CONTRACTNUM = '"+contractNum+"'")
                contractRec = contractSet.moveFirst()
                struc.setCurrentData('CONTRACTID',contractRec.getString('CONTRACTID'))
                count += 1
        finally:
            contractSet.close()