Recently, I’ve seen a lot of online posts asking IBM for the ability to be able to tie an Automation Script to the Dialog OK button. I have a solution! This blog post should allow Maximo Developers to use Automation Scripts in parallel with Dialog boxes.
The problem faced isn’t tying the action to the button (that is basic Automation Scripting functionality), the problem is closing the Dialog once the Automation Script has fired as you can only tie one action to the button and you can’t close a Dialog box from Automation Scripts as you don’t have the visibility of variables you would need. So, currently you can either close the Dialog ORfire the Automation Script.
To work around this without the need for Java Bean Classes I’ve left the okdialog action on the OK button which handles the Dialog close functionality and I have my Automation Script firing on save of the main record. With the Dialog box set to save on “UNLOAD” (close), the main record is saved as standard by Maximo once the Dialog closes and so the Automation Script is fired when the Dialog is closed.
The Requirements
In this example, we will be using a requirement to be able to copy PO Lines from any other PO to the open PO. This will be done by selecting the PO Lines to copy from a Dialog box and copying them when the Dialog box closes.
Steps to Implement
First, I created a new relationship from the PO Object to the POLINES Object. The new relationship is required for two reasons:
- To return the PO Lines we want to be able to select on the Dialog;
- To identify when the Dialog is opened from Automation.
The relationship brings back all PO Lines which aren’t currently on the open PO.
[sql] ponum != :ponum AND siteid = :siteid AND orgid = :orgid [/sql]
Next, I created the Dialog which uses the relationship to display the PO Lines.
[xml] <dialog id="copypolines" label="Copy PO Lines" parentdatasrc="MAINRECORD" relationship="ALLPOLINES" savemode="ONUNLOAD">
<table id="copypolines_table" inputmode="readonly" label="PO Lines" selectmode="multiple">
<tablebody displayrowsperpage="20" filterable="true" id="copypolines_table_tablebody">
<tablecol filterable="false" hidden="false" id="copypolines_virtualset1_tablebody_1" mxevent="toggleselectrow" sortable="false" type="event"/>
<tablecol dataattribute="ponum" id="copypolines_tablebody_1" mxevent="selectrecord" type="link"/>
<tablecol dataattribute="polinenum" id="copypolines_tablebody_4" mxevent="selectrecord" type="link"/>
<tablecol dataattribute="description" id="copypolines_table_tablebody_2"/>
</tablebody>
</table>
<buttongroup id="copypolines_2">
<pushbutton default="true" id="copypolines_2_1" label="OK" mxevent="dialogok"/>
<pushbutton id="copypolines_2_2" label="Cancel" mxevent="dialogcancel"/>
</buttongroup>
</dialog>[/xml]
Important things to notes about the Dialog:
- The Parent Data source is set to MAINRECORD. This is so the relationship runs off the open PO Record.
- The Relationship is set to the one we created earlier. This Dialog will be the only place this Relationship is used in Maximo, so we can identify when the Dialog is launched in Automation.
- The OK Button has an MX Event of
- The Save Mode is set to ONUNLOAD meaning the dialog will save the main record when OK is pressed.
Next, we need to create an Automation Script to tell the PO to do something on Save. This Automation Script has a basic Object Launch Point on Object PO before save for Add and Updates.
The Automation Script fired on PO does the following steps:
- Get all the selected PO Lines from the Dialog using the ALLPOLINES relationship defined and used above.
- Loop through the selected lines and copies Line Type and Description to new lines on the current PO.
[python] #Get all selected PO Lines
selectedMBOs = mbo.getMboSet(“ALLPOLINES”)
selectedMBOs.resetWithSelection()
#Return the first selectet PO Line
selectedMbo = selectedMBOs.moveFirst()
#Create a PO Line MBO Set from the current PO so we can add new lines to it
poLines = mbo.getMboSet(“POLINE”)
#Loop through all PO Lines which were selected on the Dialog
while selectedMbo != None :
#Add a new PO Line for the Selected Line1
newLine = poLines.add()
#Copy details from the selected line to the new line
newLine.setValue(“LINETYPE”, selectedMbo.getString(“LINETYPE”))
newLine.setValue(“DESCRIPTION”, selectedMbo.getString(“DESCRIPTION”))
#Move onto next selected line
selectedMbo = selectedMBOs.moveNext()[/python]
The final step is to tell the Dialog to mark the PO as modified so the Dialog save action will actually fire when the Dialog closes. To achieve this, I’ve created an Automation script which fires on init of the POLINE Object.
The Automation Script itself checks the Relationship being used to initialise the POLINES object is our ALLPOLINES Relationship and if it is it marks the PO’s modified flag as true.
[python] #Check relationship being used for the PO Lines MBO Set
if mbo.getThisMboSet().getRelationName() == “ALLPOLINES” :
#Mark the owning PO as Modified
mbo.getOwner().setModified(True)[/python]
Now if we open a PO (This one has no lines):
Open the Copy PO Lines Dialog and select random lines:
Now when we click OK, the lines will be copied to the PO.
0 Comments