Maximo Open Forum

 View Only
Expand all | Collapse all

Updating WO status using MX Server after saving added/updated matrectrans records in the Receiving (Receipts) Application

  • 1.  Updating WO status using MX Server after saving added/updated matrectrans records in the Receiving (Receipts) Application

    Posted 02-27-2025 10:34
      |   view attached

    I am trying to build an IBM Maximo Automation Script that executes after the user clicks "Save" in the Recieving (Receipts) Application.


    Process of adding recieved materials for a PO:
    Step 1: User goes into Receiving (Receipts) Application
    Step 2: User must select a PO
    Step 3: After selecting a PO, the user is now in the Material Receipts Tab
    Step 4: When the user recieves one or all of the Ordered Items from the selected PO, the user will click the "Select Ordered Items" Button in the Material Receipts Table in the Material Receipts Tab
    Step 5: Once the user finishes adding all of the Received Ordered Items, the user must click the "Save Button" at the top of the page to commit the updates/changes.


    The purpose of this script is that after the user saves the added received items (matrectrans records) that were ordered in the PO, for all matrectrans records that are items and are associated with a workorder, we need to check if all items ordered were recieved for each workorder in that PO so that we can update the work orders status automatically.
    1. the script needs to get a mbo set of all matrectrans records of the selected PO with the following conditions: matrectrans.ponum = the selected po's ponum, matrectrans.wonum is not null, matrectrans.siteid = the selected po's siteid, matrectrans.linetype = 'ITEM'
    2. once we have this mbo set the script then needs to get a list of the distinct work order numbers by checking the matrectrans.wonum value of each collected record in the matrectrans mbo set
    3. once we have this list of wonums, we need to get a work order mbo set with all of those workorders
    4. once we have that workorder mbo set, then we need to loop through the workorders in the work order mbo set one by one to update the status of each workorder one by one using a function.

    function logic with one parameter updateWorkOrder(workorder)
    4.1 get a POLINE mbo set of all POLINE records created for the current workorder. POLINE mbos have poline.wonum = the current workorders wonum, poline.siteid = the current workorders siteid, poline.linetype = 'ITEM'
    4.2 create a poline dictionary using the collected poline records to get all distinct items (poline.itemnum) ordered for this workorder and its total order quantity (poline.orderqty)
    4.3 get a matrectrans mbo set of all matrectrans records created for the current workorder. matrectrans mbos have matrectrans.wonum = the current workorders wonum, matrectrans.siteid = the current workorders siteid, matrectrans.linetype = 'ITEM'
    4.4 create a matrectrans dictionary using the collected matrectrans records to get all distinct items (poline.itemnum) recieved for this workorder and its total recieved quantity (matrectrans.quantity)
    4.5 update the status of the current workorder if it meets any of the following coniditions:
    - If polineDict and matrectransDict is not null and all items have been recieved then it will automatically update the status of the work order to "MATL-IN".
    - If polineDict and matrectransDict is not null but sum of the ordered items have been recieved, not all, then we need to update the status of the work order to "MATL-PIN".
    - IF polineDict is not null and matrectransDict is null, materials have been ordered but no materials have been recieved, then the status of the work order needs to be "WMATL"
    - else do not change the status of the current workorder and move on to update the next work order in the workorder mboset


    current code for Automation Script with Object Launch Point and Object Launch Point Settings

    Settings for Object Launch Point are attached in the photo.

    Logic and thought process for code:
    in the application designer for the Receiving (Receipts) Application, it says the main object is a PO
    However, I am not changing/updating any data related to the po, what I am adding/updating are matrectrans records that are in the table in the Material Recipets Tab in the Receiving Application. (At least i think this is the case)


    from psdi.server import MXServer
    from psdi.mbo import MboConstants

    mxServer = MXServer.getMXServer()
    userInfo = mbo.getUserInfo()

    # Function/Method to update the value of workorder.status in a workorder
    def updateWorkOrder(workorder):
    # Step 1: Retrieve poline records created for <workorder>
    polineSet = mxServer.getMboSet("POLINE", userInfo)
    polineSet.setWhere("SITEID = '{}' AND WONUM = '{}' AND LINETYPE = 'ITEM'".format(workorder.getString("SITEID"), workorder.getString("WONUM")))
    polineSet.reset()

    # Step 2: Populate poline dictionary with distinct ordered items and total order quantity
    polineDict = {}
    polineMbo = polineSet.moveFirst()
    while polineMbo is not None:
    itemnum = polineMbo.getString("ITEMNUM")
    orderqty = polineMbo.getDouble("ORDERQTY")
    polineDict[itemnum] = polineDict.get(itemnum, 0) + orderqty
    polineMbo = polineSet.moveNext()

    # Step 3: Retrieve matrectrans records created for <workorder>
    matrectransSet = mxServer.getMboSet("MATRECTRANS", userInfo)
    matrectransSet.setWhere("SITEID = '{}' AND WONUM = '{}' AND LINETYPE = 'ITEM'".format(workorder.getString("SITEID"), workorder.getString("WONUM")))
    matrectransSet.reset()

    # Step 4: Populate matrectrans dictionary with distinct recieved items and total recieved quantity
    matrectransDict = {}
    matrectransMbo = matrectransSet.moveFirst()
    while matrectransMbo is not None:
    itemnum = matrectransMbo.getString("ITEMNUM")
    quantity = matrectransMbo.getDouble("QUANTITY")
    matrectransDict[itemnum] = matrectransDict.get(itemnum, 0) + quantity
    matrectransMbo = matrectransSet.moveNext()

    # Step 5: Update Work Order Status
    if polineDict and matrectransDict and all(item in matrectransDict and matrectransDict[item] == polineDict[item] for item in polineDict):
    workorder.setValue("STATUS", "MATL-IN", MboConstants.NOACCESSCHECK)
    elif all(item in matrectransDict for item in polineDict) and any(matrectransDict[item] < polineDict[item] for item in polineDict):
    workorder.setValue("STATUS", "MATL-PIN", MboConstants.NOACCESSCHECK)
    elif any(item in matrectransDict for item in polineDict):
    workorder.setValue("STATUS", "MATL-PIN", MboConstants.NOACCESSCHECK)
    elif polineDict and not matrectransDict:
    workorder.setValue("STATUS", "WMATL", MboConstants.NOACCESSCHECK)
    # Else: No update needed

    # Step 1: Retrieve all matrectrans records associated with the selected PO
    matrectransSet = mxServer.getMboSet("MATRECTRANS", userInfo)
    matrectransSet.setWhere("SITEID = '{}' AND PONUM = '{}' AND LINETYPE = 'ITEM' AND WONUM IS NOT NULL".format(mbo.getString("SITEID"), mbo.getString("PONUM")))
    matrectransSet.reset()

    # Step 2: Extract unique work order numbers from matrectransSet
    wonumList = set()
    matrectransMbo = matrectransSet.moveFirst()
    while matrectransMbo is not None:
    wonum = matrectransMbo.getString("WONUM")
    if wonum:
    wonumList.add(wonum)
    matrectransMbo = matrectransSet.moveNext()

    if wonumList:
    # Step 3: Retrieve Work Orders
    woSet = mxServer.getMboSet("WORKORDER", userInfo)
    wonumFormatted = ",".join("'{}'".format(w) for w in wonumList) # Properly format the WONUMs
    woSet.setWhere("WONUM IN ({}) AND SITEID = '{}'".format(wonumFormatted, mbo.getString("SITEID")))
    woSet.reset()

    # Step 4: Update Work Orders
    woMbo = woSet.moveFirst()
    while woMbo is not None:
    updateWorkOrder(woMbo)
    woMbo = woSet.moveNext()

    # Step 5: Save Changes
    woSet.save(MboConstants.NOACCESSCHECK)



    with this setup i am getting this error:
    BMXAA6713E - The MBO fetch operation failed in the mboset with the SQL error code 207. The record could not be retrieved from the database. See the log file for more details about the error.

    what am i doing wrong here?


    #Administration
    #Architecture
    #Customizations
    #EverythingMaximo
    #Integrations
    #Inventory
    #MaximoApplicationSuite
    #Reporting

    ------------------------------
    Julio Roca
    BCBS
    ------------------------------


  • 2.  RE: Updating WO status using MX Server after saving added/updated matrectrans records in the Receiving (Receipts) Application

    Posted 02-27-2025 12:22

    You're trying to query columns on POLINE & MATRECTRANS that are non-persistent which is resulting in an invalid query. WONUM is an attribute on those tables but is non-persistent. The persistent attribute is REFWO, but it is important to understand that REFWO will contain the WONUM for the overall workorder or the task if it's at the task level.

    I would also be cautious of doing this process during the receipt because the WO costs will be updated and you'll likely hit an updated by another user error. I would try and build on top of the existing attributes like DIRISSUEMTLSTATUS



    ------------------------------
    Steven Shull
    IBM
    ------------------------------