Duplicate object scripts

You can use duplicate object scripts to perform actions when objects are duplicated. For example, you can use a duplicate object script to duplicate a custom child object when duplicating objects.

A duplicate object script is a special type of automation script without a launch point. The name of the script must be in the format OBJECTNAME.DUPLICATE or OBJECTNAME.AFTERDUPLICATE. For example, if you want to create a script to use for a purchase order (PO) you must call it PO.DUPLICATE.

By using the .DUPLICATE and .AFTERDUPLICATE events, you control the logic that occurs when records are duplicated. The following examples are scenarios where this function can be used.

  • To remove values that cannot be skipped during duplication.
  • To maintain a reference between two records.
  • To copy other child objects that might not be handled by default, for example, custom objects.

The difference between .DUPLICATE and .AFTERDUPLICATE is when the code is triggered.

.DUPLICATE occurs in the Maximo® business object (MBO) method for copying the record. Anytime duplicate() or copy() are called on the MBO, including inside an automation script or integration, the .DUPLICATE script is run. This script runs before any child data sets, such as DOCLINKS or POLINES, are copied. If you need to modify those child data sets after they are copied, you need to create a script that is named for the child data set, such as POLINE.DUPLICATE. Or, you can use the .AFTERDUPLICATE event.

.AFTERDUPLICATE is handled in the DataBean class that is extended from the non-Graphite-based user interface and the REST API action for duplicating a record. Other events that typically cause a record to be duplicated, such as calling mbo.duplicate() inside an automation script, do not cause this script to run. This limitation is important in determining whether this event can be used. .AFTERDUPLICATE occurs after all the logic for duplication occurs. For example, if the duplicate() function of an MBO copies in child data sets, those child data sets are copied when .AFTERDUPLICATE runs.

The following table describes the implicit variables for duplicate object scripts.
Table 1. Implicit variables for duplicate object scripts
Variable name Description
mbo The original MBO record that was duplicated.
dupmbo The new MBO record.
The following script is an example of a duplicate object script:
# Clear out existing values
dupmbo.setValueNull("ASSETNUM")

# Copy custom object set into new record
# NOTE: You most likely would need to update the values that point to your record, 
# such as WONUM, to the new record.
origChildSet=mbo.getMboSet("MYCUSTOMRELATIONSHIP")
origChildSet.copy(dupmbo.getMboSet("MYCUSTOMRELATIONSHIP"))