Maximo Open Forum

 View Only

 Object Structure Automation Script Inbound Processing, afterMboData(), mbo.setValue(...) Does Nothing?!

Jump to  Best Answer
  • Administration
  • Integrations
Jared Schrag's profile image
Jared Schrag posted 08-27-2024 14:24

I have the below Automation Script which is executing during the inbound processing of the Object Structure MYOBJSTRUCT. The Object Structure has WORKORDER as the top level object and the non-persistent attribute, DESCRIPTION_LONGDESCRIPTION, is included for the Object Structure, and the inbound payload includes a value for that field/attribute. The goal of the Automation Script is to update the DESCRIPTION_LONGDESCRIPTION attribute value during the afterMboData(ctx) function overload. I believe I am closely following IBM's documentation for this scenario in this article. Shockingly, after the mbo.setValue() function call, the observed value (retrieved via mbo.getString("DESCRIPTION_LONGDESCRIPTION")) seem to indicate that the attribute value was not actually changed.

What am I missing?

# OSIN.MYOBJSTRUCT

def afterMboData:
    ctxMbo = ctx.getMbo()
    struct = ctx.getData()
    if struct.isInCurrentData("DESCRIPTION_LONGDESCRIPTION"):
        # Assume the Obj Structure field DESCRIPTION_LONGDESCRIPTION has the value "some old value"
        ctxMbo.setValue("DESCRIPTION_LONGDESCRIPTION", "SOME NEW VALUE!")

        # Log shows: "New LD value: some old value"
        ctx.log("New LD value: " + ctxMbo.getString("DESCRIPTION_LONGDESCRIPTION")

Here is a screenshot from the IBM article I linked above:

Steven Shull's profile image
Steven Shull  Best Answer

This example is actually a terrible one because for it to be valid, the description field needs to be marked as restricted which it almost never is.

Look at our wiki here: https://ibm-maximo-dev.github.io/maximo-autoscript-documentation/integration/osevents

Specifically, the afterMboData section. If something comes in the MIF, Maximo sets the NOSETVALUE flag on the attribute so that other processes that might change it normally do not. You can clear this flag if you want so you can override in the afterMboData method. Or you could mark it restricted if you want to always have special processing on the long description to avoid taking it directly from the user. 

Jared Schrag's profile image
Jared Schrag

@Steven Shull, wait, another terrible example, unbelievable! Would be nice if they included all of the context for using the afterMboData callback.

/sarc

Actually, we should be so lucky that they even documented any example at all, I suppose. Thanks for your helpful reply!

Jared Schrag's profile image
Jared Schrag

Based on the wiki linked in the answer posted by @Steven Shull, I came to the understanding about the proper use of the beforeMboData() and afterMboData() callback functions defined in the Object Structure inbound processing Automation Script. What I was failing to grasp was that because I was using afterMboData(), the MIF had already set the Mbo attribute I was wanting to update using an access modifier that prevented further changes by any process, including my code in the afterMboData() callback.

Instead, I ended up implementing the beforeMboData() callback, which allows me to set the Mbo attribute, but I need to ensure that I use the appropriate access modifier so that the MIF process does not overwrite my implementation (see my new code example below):

# OSIN.MYOBJSTRUCT

def beforeMboData:
    struct = ctx.getData()
    if struct.isInCurrentData("DESCRIPTION_LONGDESCRIPTION"):
        ctxMbo = ctx.getMbo()

        # Assume the Obj Structure field DESCRIPTION_LONGDESCRIPTION has the value "some old value"
        ctxMbo.setValue("DESCRIPTION_LONGDESCRIPTION", "SOME NEW VALUE!", MboConstants.DELAYVALIDATION)

        # The Mbo attribute now is updated and will prevent any other modification by further MIF processing that executes subsequently