IBM Support

Checking if an Attribute Exists or Not on an Object via Automation Scripts

Technical Blog Post


Abstract

Checking if an Attribute Exists or Not on an Object via Automation Scripts

Body

If you need to check that an attribute (field) exists on an object (MBO) or not, then you may use the following python code pieces in your Automation Scripts:

 

Alternative 1:

mboValueData = mbo.getMboValueData(['ATTRIBUTENAME'])
if mboValueData[0] is not None:
    mbo.setValue("ATTRIBUTENAME", "NEWVALUE")

 

Alternative 2:

from psdi.security import UserInfo
from psdi.server import MXServer

mxServer = MXServer.getMXServer()
userInfo = mbo.getUserInfo()
objectName = mbo.getName()

attrSet = mxServer.getMboSet("MAXATTRIBUTE", userInfo)
attrSet.reset()
attrSet.setWhere("objectname = '" + objectName + "' and attributename = 'ATTRIBUTENAME'" )

if(not attrSet.isEmpty()):
    mbo.setValue("ATTRIBUTENAME", "NEWVALUE")

 

PS: There are other methods in Maximo framework in order to do the same check, but they return "Attribute {0} does not exist" exception and they require error handling. So the two alternatives above are the easier options.

[{"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSLKT6","label":"IBM Maximo Asset Management"},"Component":"","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"","Edition":"","Line of Business":{"code":"LOB59","label":"Sustainability Software"}}]

UID

ibm11129677