Pages

Wednesday, March 23, 2022

Automation Script Quick Reference

Here are some of the quick reference guide for every maximo developer.

Before we begin with some example, you must be aware of automation script implicit variables. Please refer to this post for detailed explanation of the implicit variables. 


Getting the attribute values

Get attribute value (current value)
description = mbo.getString("DESCRIPTION")
instDate    = mbo.getDate("INSTALLDATE")
priority    = mbo.getInt("PRIORITY")
assetuid    = mbo.getString("ASSETUID")
isrunning   = mbo.getBoolean("ISRUNNING")
linecost    = mbo.getDouble("LINECOST")

Get initial/current/previous values
descMboValue  = mbo.getMboValue("DESCRIPTION")

initialDesc    = descMboValue.getInitialValue().asString()
currentDesc    = descMboValue.getCurrentValue().asString()
previousDesc  = descMboValue.getPreviousValue().asString()

Setting the attribute value

Set attribute value
mbo.setValue("DESCRIPTION", "New Description")
mbo.setValue("INTERNAL", True)
mbo.setValue("PRIORITY", 2)
mbo.setValueNull("DESCRIPTION")

Set attribute value with modifiers
from psdi.mbo import MboConstants

mbo.setValue("DESCRIPTION", "New Description", MboConstants.NOACCESSCHECK)
mbo.setValue("INTERNAL", False, MboConstants.NOVALIDATION)
mbo.setValueNull("DESCRIPTION", MboConstants.NOACTION)
mbo.setValue("PRIORITY", 2, MboConstants.NOVALIDATION_AND_NOACTION)

Changing status of an mbo

from psdi.server import MXServer
from psdi.server import MboConstants

mxserver = MXServer.getMXServer()

mbo.changeStatus("APPR", mxserver.getDate(), "Memo", MboConstants.NOACCESSCHECK)

MboSet Operations

Get current MboSet
prlineSet = mbo.getThisMboSet()

Get MboSet from relationship
prlineSet = mbo.getMboSet("PRLINE")

Get MboSet from MXServer
from psdi.server import MXServer

mxserver = MXServer.getMXServer()

# To Fetch the user information from mbo 
userInfo = mbo.getUserInfo()
# To Fetch the system user (admin/super user) information from MXServer
userInfo = mxserver.getSystemUserInfo()
# To fetch the user information from the request caller (in case the script is used for services)
userInfo = request.getUserInfo()


prSet = mxserver.getMboSet("PR", userInfo)
prSet.setWhere("PRNUM='1001'")
prSet.reset()


# Close the set if called from server
prSet.clear()
prSet.close()

Get the MboSet count
count = prSet.count()

Add Mbo (record) to MboSet
prlineSet = pr.getMboSet("PRLINE")
prline = prlineSet.addAtEnd()
prline.setValue("ITEMNUM", "PUMP100")

Check if the MboSet is empty
if mbo.getMboSet("PRLINE").isEmpty():

Looping through MboSet

Loop with MboSet count
prlineSet = mbo.getMboSet("PRLINE")

for i in range(0, prlineSet.count()):
    prline = prlineSet.getMbo(i)
    

Loop with moveFirst/moveNext (recommended)
prlineSet = mbo.getMboSet("PRLINE")

prline = prlineSet.moveFirst()
while prline:
    prline = prlineSet.moveNext()

Raise Error

Using errorgroup and errorkey (before Maximo 7.6)
params = [mbo.getString("ITEMNUM")]
errorgroup = "msgGroup"
errorkey = "msgKey"

Using service object (Maximo 7.6 and later)
params = [mbo.getString("ITEMNUM")]
# With parameters
service.error("msgGroup", "msgKey", params)
# Without paramters
service.error("msgGroup", "msgKey")

Logging

Using serivce object
service.log_warn("Warning logs")
service.log_info("Info logs")
service.log_debug("Debug logs")

Custom logger
from psdi.util.logging import MXLoggerFactory
mxlogger = MXLoggerFactory.getLogger("maximo.customlogger")
mxlogger.warn("Warning logs")
mxlogger.info("Info logs")
mxlogger.error("Error logs")
mxlogger.debug("Debug logs")

No comments:

Post a Comment