Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

IBM M AXIMO A UTOMATION S CRIPTS Q UICK R EFERENCE (1.

1) 1

I MPLICIT V ARIA BLES S ET A TTRIBUTES

▪ app - name of the application that the script is running against. Set attribute value
▪ errorgroup/errorkey/params . Used to raise an error (see examples).
mbo.setValue("DESCRIPTION", "New description")
▪ interactive - Indicates whether the script is running in an active user session or a non-user mbo.setValueNull("DESCRIPTION")
background session, such as integration transaction processing.
▪ mbo - the MBO that is being worked on. Set attribute value with modifiers
▪ mboname - the name of the current MBO in the context of the script that is running.
▪ mbovalue - instance of the MBO attribute (attribute launch point only). from psdi.mbo import MboConstants
mbo.setValue("DESCRIPTION", "New description", MboConstants.NOACCESSCHECK)
▪ onadd/ondelete/onupdate - indicates whether the business object that the script is running mbo.setValue("DESCRIPTION", "New description", MboConstants.NOVALIDATION)
against is being inserted/created/deleted/updated. mbo.setValue("DESCRIPTION", "New description", MboConstants.NOACTION)
▪ user - the userid of the user who is logged in. mbo.setValue("DESCRIPTION", "New description", MboConstants.NOVALIDATION_AND_NOACTION)
▪ userinfo - reference to UserInfo for the current context.
▪ service - utility class with useful methods. Set field metadata (required, read-only)
Examples below. Full list of implicit variables here. from psdi.mbo import MboConstants
mbo.setFieldFlag("FROMSTORELOC", MboConstants.READONLY, False)
mbo.setFieldFlag("FROMSTORELOC", MboConstants.REQUIRED, True)

G ET A TTRI BUTES

Get attribute value M BO S ET


desc = mbo.getString("DESCRIPTION")
wopri = mbo.getInt("WOPRIORITY")
Get current MboSet
woid = mbo.getLong("WORKORDERID") woSet = mbo.getThisMboSet()
value = mbo.getDouble("MEASUREMENTVALUE")
targd = mbo.getDate("TARGSTARTDATE")
Get MboSet from relationship
hasp = mbo.getBoolean("HASPARENT")
woSet = mbo.getMboSet("WORKORDER")
Get initial/current/previous value
Get MboSet from MXServer (breaks transaction)
mbo.getString("DESCRIPTION") # easy way to get the current value
# the MboValue object provide the 3 values from psdi.server import MXServer
mboValue = mbo.getMboValue("DESCRIPTION") woSet = MXServer.getMXServer().getMboSet("WORKORDER", mbo.getUserInfo())
initValue = mboValue.getInitialValue().asString() woSet.setWhere("WONUM='1000'")
currValue = mboValue.getCurrentValue().asString()
prevValue = mboValue.getPreviousValue().asString() Check if MboSet is empty
Check attribute value if mbo.getMboSet("WORKORDER").isEmpty():

if mbo.getString("STATUS") == 'APPR':
Count records in an MboSet
Check if attribute is null count = mbo.getMboSet("WORKORDER").count()

if mbo.isNull("DESCRIPTION"): Add record to MboSet


Check if attribute has been modified polines = po.getMboSet("POLINE")
poline = polines.add()
If mbo.isModified("DESCRIPTION "): poline.setValue("ITEMNUM", "PUMP100")

Copyright © 2019 Bruno Portaluri (MaximoDev) - Download the latest version of the guide: https://bportaluri.com/automation-scripts-quick-reference
IBM M AXIMO A UTOMATION S CRIPTS Q UICK R EFERENCE (1.1) 2

L OOPING THROUGH M BO S ET L OGGI NG

Loop with for/count With service object


woSet = session.getMboSet('WORKORDER') service.log_warn("Warning message")
for i in range(0, woSet.count()): service.log_info("Informational message")
wo = woSet.getMbo(i) service.log_debug("Debug message")
print "Workorder ", wo.getString("WONUM")
Custom logger
Loop with moveFirst/moveNext (preferred)
from psdi.util.logging import MXLoggerFactory
woSet = mbo.getMboSet("WORKORDER") logger = MXLoggerFactory.getLogger("maximo.mxdev")
wo = woSet.moveFirst() logger.debug("Debug message") # error/warn/info/debug
while (wo):
print "Workorder ", wo.getString("WONUM")
wo = woSet.moveNext()
E X EC UT E S CR IP T ONLY I F R U NNI NG F R OM GUI

if interactive == True:
R AISE E RROR # Things to do if script is running in user Context
else:
Setting errorgroup/errorkey (Maximo 7.5) # Things to do if script is called by Crontask, MIF, ...
params = [mbo.getString("ASSETNUM")]
errorgroup = "msggroup"
errorkey = "msg"
R EADING S YSTEM P ROPERTY
With service object (Maximo 7.6)
from psdi.server import MXServer
params = [mbo.getString("ASSETNUM")] configData = MXServer.getMXServer().getConfig()
service.error("msggroup", "msg", params) maxProperty = configData.getProperty("mail.smtp.host")

Y ES /N O /C ANCEL S AVING M BO S ET

def yes(): Calling MboSet.save() method is not required when using relationships
# handle Yes button press
def no(): woSet = mbo.getMboSet("WORKORDER")
# handle No button press wo = woSet.getMbo(0)
def dflt(): wo.setValue("DESCRIPTION", "New")
# display the initial message woSet.save() # this is not required!
service.yncerror("msggroup", "msg")
cases = {service.YNC_NULL:dflt, service.YNC_YES:yes, service.YNC_NO:no} The MxServer.getMboSet breaks the transaction so save() is required
if interactive:
woSet = MXServer.getMXServer().getMboSet("WORKORDER", mbo.getUserInfo())
# service yncuserinput method to trigger the interaction
woSet.setWhere("WONUM='1000'")
x = service.yncuserinput()
wo = woSet.getMbo(0)
# process user input using case statement
mbo.setValue("DESCRIPTION", "New Test Asset!")
cases[x]()
woSet.save()

Copyright © 2019 Bruno Portaluri (MaximoDev) - Download the latest version of the guide: https://bportaluri.com/automation-scripts-quick-reference

You might also like