You are on page 1of 2

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

0) 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
background session, such as integration transaction processing. Set attribute value with modifiers
▪ mbo - the MBO that is being worked on.
▪ mboname - the name of the current MBO in the context of the script that is running. from psdi.mbo import MboConstants
▪ mbovalue - instance of the MBO attribute (attribute launch point only). mbo.setValue("DESCRIPTION", "New description", MboConstants.NOACCESSCHECK)
mbo.setValue("DESCRIPTION", "New description", MboConstants.NOVALIDATION)
▪ onadd/ondelete/onupdate - indicates whether the business object that the script is running mbo.setValue("DESCRIPTION", "New description", MboConstants.NOACTION)
against is being inserted/created/deleted/updated. mbo.setValue("DESCRIPTION", "New description", MboConstants.NOVALIDATION_AND_NOACTION)
▪ user - the userid of the user who is logged in.
▪ userinfo - reference to UserInfo for the current context. Set field metadata (required, read-only)
▪ service - utility class with useful methods.
from psdi.mbo import MboConstants
Examples below. Full list of implicit variables here. mbo.setFieldFlag("FROMSTORELOC", MboConstants.READONLY, False)
mbo.setFieldFlag("FROMSTORELOC", MboConstants.REQUIRED, True)

G ET A TTRI BUTES
M BO S ET
Get attribute value
desc = mbo.getString("DESCRIPTION")
Get current MboSet
wopri = mbo.getInt("WOPRIORITY") woSet = mbo.getThisMboSet()
woid = mbo.getLong("WORKORDERID")
value = mbo.getDouble("MEASUREMENTVALUE")
Get MboSet from relationship
targd = mbo.getDate("TARGSTARTDATE")
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 from psdi.server import MXServer
# the MboValue object provide the 3 values woSet = MXServer.getMXServer().getMboSet("WORKORDER", mbo.getUserInfo())
mboValue = mbo.getMboValue("DESCRIPTION") woSet.setWhere("WONUM='1000'")
initValue = mboValue.getInitialValue().asString()
currValue = mboValue.getCurrentValue().asString() Check if MboSet is empty
prevValue = mboValue.getPreviousValue().asString()
if mbo.getMboSet("WORKORDER").isEmpty():
Check attribute value
Count records in an MboSet
if mbo.getString("STATUS") == 'APPR':
count = mbo.getMboSet("WORKORDER").count()
Check if attribute is null
Add record to MboSet
if mbo.isNull("DESCRIPTION"):
polines = po.getMboSet("POLINE")
Check if attribute has been modified poline = polines.add()
poline.setValue("ITEMNUM", "PUMP100")
If mbo.isModified("DESCRIPTION "):

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.0) 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