Maximo Open Forum

 View Only

 Automation Script add new row on child table from button

Jump to  Best Answer
  • Maximo Application Suite
Eric Burkland's profile image
Eric Burkland posted 06-04-2025 19:38

Good Evening all,

I have custom buttons which add Labor Records on Work orders and default values.  I accomplished this with a traditional Java customization in the past.  Now these customizations are not working properly after I apply the May 2025 update for MAS/Manage 9.0.

Does anyone have a complete example of how to add an automation script to a button on a child record?  I cannot get it to execute for the life of me.

UPDATE:  
Here's how I solved my issue by following the link Alex provided https://www.linkedin.com/pulse/ibm-mas-manage-ui-bean-scripting-andrzej-wieclaw-4vtbf/
Thanks to others for the suggestions, I'm sure there are multiple ways of doing this.

  1. Set System Property mxe.script.allowbeanscript = 1
  2. Create an automation script named DATABEAN.<custom-name>  Ex: DATABEAN.WOTRACK.ACTUALS.LABOR
    1. Be sure to check the "Allow Invoking Script Functions?" checkbox
    2. For DataBeans you have to add variables to the script with Variable Type "IN" and Binding Type LITERAL
      1. beanid = actuals_actuals_aclabor_aclabor_table    You find this in the application XML. IN my case this was the id of the <table>
      2. beanapp = WOTRACK
    3.  The function inside your script has to have the same as the the mxevent.  In my case mxevent="addrowWithLabor"

from psdi.server import MXServer

def addrowWithLabor(ctx):
    mxserver = MXServer.getMXServer()
    control = ctx.getEvent().getSourceControlInstance()
    databean = control.getDataBean()

    rowadd = databean.addrow()
    ltmbo = databean.getMbo()
    currentuser = ltmbo.getUserInfo()
    personid = currentuser.getPersonId()
    try:
        personset = mxserver.getMboSet("PERSON", currentuser)
        personset.setWhere("personid = '" + personid + "'")
        personset.reset()
        if not personset.isEmpty() and not personset.getMbo(0).isNull("locationorg"):
            laborset = mxserver.getMboSet("LABOR",currentuser)
            laborset.setWhere("orgid = '" + personset.getMbo(0).getString("locationorg") + "' and personid = '" + personid + "'")
            laborset.reset()
            if not laborset.isEmpty() and not laborset.getMbo(0).isNull("laborcode"):
                ltmbo.setValue("LABORCODE",laborset.getMbo(0).getString("laborcode"))
                
    finally:
        laborset.cleanup()
        laborset.close()
        personset.cleanup()
        personset.close()

Alex Walter's profile image
Alex Walter  Best Answer

A good summary of UI Scripting and its capabilities is found here:

https://www.linkedin.com/pulse/ibm-mas-manage-ui-bean-scripting-andrzej-wieclaw-4vtbf/

Hope this helps,

Alex

Niv Geo's profile image
Niv Geo

Hi Eric

Situations and Scenarios can vary but could you pass a screen shot or sample code of what you are trying to achieve.

Eric Burkland's profile image
Eric Burkland

@Alex Walter Hope you are doing well and thank you for the information!  This is very interesting.  I actually figured out that on a child record I could get the code to execute but only when there were 1 or more rows in the table.  If there were zero rows it would not execute.  This suggests to me what your article describes which is there are limitations on the traditional automation scripting classes and events.  I'll have to explore some of these new avenues.  

Thanks again,
Eric

Jade Warren's profile image
Jade Warren

I have solved this problem by opening the application XML in an editor and then putting a SECTION control below the table details.  You can then set the data source ID of the SECTION = mainrecord and place your action button (to add the row + set values) w/in that section.  Then, the button push will work 100% of the time, even if there are not yet any child rows in the table.

sun kim's profile image
sun kim

I used an automation script here

https://moremaximo.com/question/automation-script-to-add-labor-hours-more-easily

Karthik Hubballi's profile image
Karthik Hubballi

I ran into a very similar issue in MAS 9 while converting a PR customization from Java to Bean Scripts.

In my case, the button was on a child table in the PR application (PR Lines tab). I had created an APPBEAN.PR script with a function matching the mxevent, enabled mxe.script.allowbeanscript, and checked "Allow Invoking Script Functions?". However, the script never executed even though the same approach worked for buttons elsewhere in the application.

After quite a bit of troubleshooting, I found that the problem was not the script itself, but the UI XML context.

The button was defined inside a <buttongroup> on a child table. What finally made it work was explicitly setting the correct targetid and datasrc/sigoptiondatasrc so that the event was routed back to the proper bean context.

For example, I had something similar to:

<buttongroup datasrc="MAINRECORD" id="prlines_prlines_table_2" sigoptiondatasrc="prlines_prlines_table">
    <pushbutton label="Punch Out" mxevent="PUNCHOUT" targetid="MAINRECORD"/>
</buttongroup>

Once the button context was corrected, my existing bean script started firing without any additional changes.

My final setup was:

  • mxe.script.allowbeanscript = 1

  • Automation script named APPBEAN.PR

  • "Allow Invoking Script Functions?" enabled

  • Function name matching the mxevent

  • Correct targetid

  • Correct datasrc / sigoptiondatasrc on the button or button group

If your script works from menus or header buttons but not from a pushbutton inside a child table, I would recommend checking the XML context first. In my case, the missing/incorrect targetid and datasource configuration were the reason the event was never reaching the bean script.

I hope this helps.