Transcription of Maximo Automation Scripts Quick Reference
1 IBM MAX I MO AUT OMAT I ON SC RI PTS QUI CK REFEREN C E ( ) 1 Copyright 2019-2020 Bruno Portaluri (MaximoDev) - Download the latest version of the guide : IM P L I C I T VA R I A B L E S app - name of the application that the script is running against errorgroup/errorkey/params - Used to raise an error (see examples) interactive - Indicates whether the script is running in an active user session or a non-user background session, such as integration transaction processing mbo - the MBO that is being worked on 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)
2 Onadd/ondelete/onupdate - indicates whether the business object that the script is running against is being created/deleted/updated user - the userid of the user who is logged in service - utility class with useful methods Examples below. Full list of implicit variables here. GET AT T R I B U T E S Get attribute value desc = ("DESCRIPTION") wopri = ("WOPRIORITY") woid = ("WORKORDERID") value = ("MEASUREMENTVALUE") targd = ("TARGSTARTDATE") hasp = ("HASPARENT") Get initial/current/previous value ("DESCRIPTION") # easy way to get the current value # the MboValue object provide the 3 values mboValue = ("DESCRIPTION") initValue = ().
3 AsString() currValue = ().asString() prevValue = ().asString() Check attribute value if ("STATUS") == "APPR": Check if attribute is null if ("DESCRIPTION"): Check if attribute has been modified If ("DESCRIPTION"): SET AT T R I B U T E S Set attribute value ("DESCRIPTION", "New description") ("DESCRIPTION") Set attribute value with modifiers from import MboConstants ("DESCRIPTION", "New description", ) ("DESCRIPTION", "New description", ) ("DESCRIPTION", "New description", ) ("DESCRIPTION", "New description", ) Set field metadata (required, read-only) from import MboConstants ("DESCRIPTION", , False) ("DESCRIPTION", , True) MBOSET Get current MboSet woSet = () Get MboSet from relationship woSet = ("WORKORDER") Get MboSet from MXServer (breaks transaction) from import MXServer woSet = ().
4 GetMboSet("WORKORDER", ()) ("WONUM='1000'") Check if MboSet is empty if ("WORKORDER").isEmpty(): Count records in an MboSet count = ("WORKORDER").count() Add record to MboSet polines = ("POLINE") poline = () ("ITEMNUM", "PUMP100") IBM MAX I MO AUT OMAT I ON SC RI PTS QUI CK REFEREN C E ( ) 2 Copyright 2019-2020 Bruno Portaluri (MaximoDev) - Download the latest version of the guide : LO O P I N G T H R O U G H MBOSET Loop with for/count woSet = ("WORKORDER") for i in range(0, ()): wo = (i) print "Workorder ", ("WONUM") Loop with moveFirst/moveNext (preferred) woSet = ("WORKORDER") wo = () while (wo): print "Workorder ", ("WONUM") wo = () RA I S E ER R O R Setting errorgroup/errorkey ( Maximo ) params = [ ("ASSETNUM")] errorgroup = "msggroup" errorkey = "msg" With service object ( Maximo ) params = [ ("ASSETNUM")] ("msggroup", "msg", params) YES/NO/CA N C E L def yes(): # handle Yes button press def no(): # handle No button press def dflt(): # display the initial message ("msggroup", "msg") cases = { :dflt, :yes, :no} if interactive.
5 # service yncuserinput method to trigger the interaction x = () # process user input using case statement cases[x]() LO G G I N G With service object ("Warning message") ("Informational message") ("Debug message") Custom logger from import MXLoggerFactory logger = (" ") ("Debug message") # error/warn/info/debug EX E C U T E S C R I P T O N L Y I F R U N N I N G F R O M G U I if interactive == True: # Things to do if script is running in user Context else: # Things to do if script is called by Crontask, MIF, .. RE A D I N G SY S T E M PR O P E R T Y from import MXServer configData = ().
6 GetConfig() maxProperty = (" ") SA V I N G MBOSET Calling () method is not required when using relationships woSet = ("WORKORDER") wo = (0) ("DESCRIPTION", "New description") () # this is not required! The breaks the transaction so save() is required woSet = ().getMboSet("WORKORDER", ()) ("WONUM='1000'") wo = (0) ("DESCRIPTION", "New description") ()