Maximo Integration and Scripting

 View Only

Multi-Select Support via Automation Scripts

By Steven Shull posted Wed June 01, 2022 08:15 AM


I've been asked a few times for how to enable multi-select with automation scripts so I wanted to document it in a blog post for others to find.  I'm going to provide a little background and then provide an end to end example on how to configure.

There are scenarios in Maximo where a user might want to be able to select multiple values from a dialog to associate to a record. For example, in the Purchase Order application you can select 1 or more Purchase Requisition lines to copy over to the Purchase Order. When you need functionality like this in your own application, this has been hard to do well with automation scripts even though most of the functionality has been available since 7.5 because you weren't able to close the dialog for the user from your automation script. With the additional functionality added to Automation Scripts to support UI interactions in 7.6.1.X of Maximo, this is now easy to do without java classes while still providing a good user experience.

My example will enable a user to select multiple assets in a lookup dialog and associate the selected assets as a comma separated list to a new custom attribute on WORKORDER. Instead of an attribute storing a comma separated list, if you're actually looking to implement this I would recommend storing each selection on a child object instead. The advantage to a child object is you can easily index & search for 

Steps to Implement
1) Create an attribute (EMXSELECTEDASSETS) on the WORKORDER object with a length of 250 characters to support selecting multiple values. Again, I would NOT recommend this approach for an actual implementation due to the inability to index and search on this data effectively. You should utilize a child object instead of a single attribute. 
2) Create a dialog in the library.xml that references the MultiselectDataBean. My example is below. Note that the datasrc for the dialog itself is MAINRECORD (IE the WO record that we’re starting from). The table utilizes a relationship (ALLASSETS) to determine which assets to be displayed for the WORKORDER. The default button is emxselassets which will correspond to our signature option & automation script. Because I associated this as a lookup to my attribute I had to add "lookup_" to the ID. It’s just a naming standard when referencing a lookup that exists in the library.xml. When you refer to the lookup in the application you do NOT provide lookup_, just the value after (emxassetlookup in this case).

<dialog beanclass="psdi.webclient.system.beans.MultiselectDataBean" id="lookup_emxassetlookup" label="Select Assets" datasrc="MAINRECORD">
    <table id="emxselassets_table" label="Assets" selectmode="multiple" relationship="ALLASSETS">
        <tablebody displayrowsperpage="15" filterable="true" id="emxselassets_table_tablebody" inputmode="readonly">
            <tablecol filterable="false" hidden="false" id="emxselassets_table_tablebody_1" mxevent="toggleselectrow" sortable="false" type="event"/>
            <tablecol dataattribute="assetnum" id="emxselassets_table_tablebody_2"/>
            <tablecol dataattribute="description" id="emxselassets_table_tablebody_3"/>
            <tablecol dataattribute="siteid" id="emxselassets_table_tablebody_4" lookup="site"/>
    <buttongroup id="emxselassets_2">
        <pushbutton default="true" id="emxselassets_2_1" label="Select Assets" mxevent="emxselassets"/>
        <pushbutton id="emxselassets_2_2" label="Cancel" mxevent="dialogcancel"/>

3) In the application (my example is WOTRACK), create a new signature option that will be the same name as your automation script action. In my case, the EMXSELASSETS. Make sure that you choose "this is an action that must be invoked by the user in the UI" so the script will fire.

Adding new signature option
4) Add your field and the lookup to the application (WOTRACK in my example). NOTE that I choose to make mine read-only so the data had to be returned via lookup.

New field in Application Designer
5) Next we need to create the automation script with action launch point.
Launch Point: Action
Language: Jython 
if databean: 

    if selectedRecords:
        while iterator.hasNext():
This automation script takes advantage of functionality added in 7.6.1.X to be able to get our user's session for interacting with the UI. This includes being able to get the data bean in the dialog in the dialog by referencing the ID of the table and calling service.closeDialog() at the end for closing the dialog automatically for the user. 

When you use the multiselect bean, it "selects" the record inside of the set. That allows us to utilize the MboSet getSelection() function to return the MBOs that the user has selected. We iterate through that list and append the ASSETNUM of each record to a list. We utilize a python function ",".join(assetList) to take the values in our list and make it a comma separated string for setting our attribute. Because our data source for the dialog itself was MAINRECORD (IE the WO), the implicit variable mbo the automation script framework adds is our WO so we can use that to set our field.