Multiple Select in Maximo

Selecting single select items in maximo is piece of cake but configuring multiple select takes some customization to be implemented.

In this tutorial I will guide in creating Multiple select in Maximo.

Requirement

I had a requirement to enable Multi-select in a lookup. The user should be able to select Multiple options from the list. All the selected option should be entered in a list as a comma separated list in a single text box.

Implementation

  1. Add values in Libraries
    For our this custom multi select menu we need to add some code in Library and Lookup.
    Go to Application designer click on Select Action drop down. There select export System XML.CropperCapture[131]This will open the following dialog.
    CropperCapture[132]
    In the dialog click the arrow against lookups and library. This will download lookups.xml and library.xmla. Lookup.xml
    We need to create a custom lookup for our requirement.  For this open lookups.xml
    Insert in the bottom of the file the following lines

    
    <table id="multicustomlookup" inputmode="readonly" selectmode="multiple">
     <tablebody displayrowsperpage="20" filterable="true" filterexpanded="true" id="multicustomlookup_">
     <tablecol dataattribute="value" id="multicustomlookup_value_multiple" labelcss="txtbold txtitalic" mxevent="selectrecord" mxevent_desc="Go To %1" sortable="true"/>
     <tablecol dataattribute="description" id="multicustomlookup_desc_multiple" sortable="true"/>
     </tablebody>
     </table>]

    Save the file

    b. Library.xml
    Open Library.xml. In this file search for this code snippet

     
    <dialog beanclass="psdi.webclient.system.beans.LookupBean" icon="img_lookup.gif" id="query_lookup" label="Select Value"> 
    <lookup id="querylookupcontrol"/> <buttongroup id="querylookup_3"> 
    <pushbutton default="true" id="querylookup_3_1" label="OK" mxevent="dialogok"/> 
    <pushbutton id="querylookup_3_2" label="Cancel" mxevent="dialogcancel"/> </buttongroup> 
    </dialog>

    Replace it with the following code.
    [code language="xml"] <dialog beanclass="com.innovise.mobilink.maximo.webclient.MLMultiSelect" icon="img_lookup.gif" id="query_lookup" label="Select Value">
    <lookup id="querylookupcontrol"/>
    <buttongroup id="querylookup_3">
    <pushbutton default="true" id="querylookup_3_1" label="OK" mxevent="dialogok"/>
    <pushbutton id="querylookup_3_2" label="Cancel" mxevent="dialogcancel"/>
    </buttongroup>
    </dialog><dialo 
    [/code]
    Save the file and import both files (lookups.xml and library.xml) back in to maximo by using the import application definition in Maximo.

  2. Application DesignerIn application designer open the application you need to edit.
    Select the attribute you want to edit. Right click – Properties.
    In the lookup field insert “multicustomlookup” without quotes. Save the application.
    CropperCapture[134]
  3. Java Code
    Create a new class file. Past the the following code in it.

    /**
     * Created by Rana Ahmed on 4/25/2016.
     * For Multi Selection in Domains
     */
    
    import psdi.mbo.MboConstants;
    import psdi.mbo.MboRemote;
    import psdi.util.MXException;
    import psdi.webclient.system.beans.LookupBean;
    import psdi.webclient.system.controller.Utility;
    
    import java.rmi.RemoteException;
    import java.util.Iterator;
    import java.util.Vector;
    
    public class MLMultiSelectTest extends LookupBean {
        private static String comma = ", ";
    
        public void initialize() throws MXException, RemoteException {
            /* This is called to select the values when the dialog is initialized. It will loop through the comma seperated values and select them in the dialog.*/
            super.initialize();
            String fieldToSet = getParent().getReturnAttribute();
            MboRemote mbo = this.app.getDataBean().getMbo();
            String value = mbo.getString(fieldToSet);
            String values[] = value.trim().split("\\s*,\\s*");
            for (int i = 0; i < values.length; i++) {
                for (int j = 0; j < getMboSet().count(); j++) {
                    if (values[i].trim().equalsIgnoreCase(getMboSet().getMbo(j).getString("value").trim())) {
                        getMboSet().select(j);
                    }
                }
            }
    
        }
    
        public int execute() throws MXException, RemoteException {
            /*This selects the iterates the values and inserts them as a comma seperated list */
            boolean onListTab = this.app.onListTab();
            if (onListTab)
                return super.execute();
    
            String commaString = new String();
            String fieldToSet = getParent().getReturnAttribute();
    
            Vector<?> selectedRecords = getMboSet().getSelection();
            Iterator<?> selectionIterator = selectedRecords.iterator();
            while (selectionIterator.hasNext()) {
                MboRemote currentSelectedValue = (MboRemote) selectionIterator.next();
    
                if (commaString.length() == 0)
                    commaString = currentSelectedValue.getString("VALUE");
                else
                    commaString += comma + currentSelectedValue.getString("VALUE");
            }
    
    
            //custom for Specific Fields
            //Use it if you want to process some custom rules.e.g. If a user selects a specific value, he cannot select any other value with it.
            //In my requirement if the user selects "Not Applicable" then he should not select any other value with it.
            if (fieldToSet.equalsIgnoreCase("MYCUSTOMFIELD") && commaString.contains("Not Applicable")) {
                if (!commaString.equalsIgnoreCase("Not Applicable")) {
                    String parms[] = new String[1];
                    parms[0] = "ABC";
                    Utility.showMessageBox(sessionContext.getCurrentEvent(), "myapp", "notapplicable", parms);
                    return 0;
                }
            }
    
            //End Custom Specific Rules
    
            MboRemote mbo = this.app.getDataBean().getMbo();
            mbo.setValue(fieldToSet, commaString, MboConstants.NOVALIDATION);
            app.getAppBean().refreshTable();
            return 1;
        }
    
    }
    
    

4. Deploy the code and restart Maximo
5. Check
Open you application and try selecting some multi select values. It should now paste them as comma seperated list.
CropperCapture[136]
Click again on lookup icon and it should display those comma separated values as selected values.
CropperCapture[137]

Thanks to this blog for much help

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s