Validate and action events
You can customize the asset Maximo® business
object (MBO) by adding custom business logic that is based on the asset purchase price or attribute
purchaseprice
in asset value. For example, you can set the vendor field to be
required or not required based on the purchaseprice
attribute value and also to
calculate the replacement cost based on the purchase price. And you can ensure that the purchase
price does not exceed a maximum allowed value.
The logic must be injected at the modification of the purchaseprice
attribute
value, which implies that it is modeled as an attribute launch point. A validation element exists in
the requirement, where the purchaseprice
cannot exceed a certain limit. An action
element is also available in which the state of the vendor
attribute and the
replacementcost
value is set based on the purchaseprice
value. The
first requirement of validation needs to be handled by the attribute validate event. The second
requirement needs to be handled in the attribute action event.
if purchaseprice > 200:
service.error("some","error")
You can use the implicit variable purchaseprice, which is the attribute that the launch point is based on, and also use service.error(..) to produce the necessary MXException for this validation.
if purchaseprice >= 100:
vend_required=True
else:
vend_required=False
rc = purchaseprice/2
vend
for the vendor attribute and rc
for the replacement cost
attribute. By using the implicit variable vend_required, you can control the
state of the vendor attribute to be required or not required. You can also set the replacement cost
by setting rc
. To do these tasks without using any of these
explicitly defined variables, use the standard MBO APIs and the implict mbo
variable. from psdi.mbo import MboConstants
if purchaseprice >= 100:
mbo.setFieldFlag("vendor",MboConstants.READONLY, True)
else:
mbo.setFieldFlag("vendor",MboConstants.READONLY, False)
mbo.setValue("replacementcost",purchaseprice/2)
replacementcost
field is read-only, both scripts fail because the MBO framework rejects the
setValue
call on that attribute. A possible workaround is to use the Suppress
Access Control variable binding metadata. By setting this metadata, the scripting framework can set
the rc
variable value to the replacementcost
whether it is read-only or not. However, this workaround works only if the script code uses the
variable binding. For scripts that use the MBO APIs, the script code must use the MboConstants
setting to achieve the same
result.from psdi.mbo import MboConstants
..
mbo.setValue("replacementcost",purchaseprice/2, MboConstants.NOACCESSCHECK)
sparepart
total quantity calculation near real-time. For example, if you change the
quantities of the related spare parts, you see the calculated field sparepartqty
value change in near real-time. To achieve this outcome, you need to create a script and attribute
launchpoint for the quantity
attribute for the sparepart
object
with the Action
event. The explicit variable binding is shown in the following
table:
Variable name | Variable type | Binding |
---|---|---|
sptqt | INOUT | &owner&.sparepartqty |
sparepartqty
attribute. Set the sptqt variable with no access
check because it is marked as read-only by the original object launch point script when the asset
MBO is initialized. The variable quantity is implicitly injected in the script because that is the
attribute on which the script is listening. The following script is an
example:sptqt=sptqt+quantity-quantity_previous
The use of the implicit variable quantity_previous represents the value of the
quantity attribute before the modification, which is the value at the initialization of the
sparepart MBO. The variable quantity
holds the current modified
value of the quantity attribute.
The script and the object launch point script provide a complete calculated field logic.