Get attribute values from Script

person writing on notebook

There are several ways to get the value of an attribute, I detail some of them below.

Get current value

mbo.getString("ASSETNUM")
mbo.getInt("PRIORITY")
mbo.getDouble("REPLACECOST")
mbo.getDate("INSTALLDATE")
mbo.getBoolean("ISRUNNING")
mbo.getLong("ASSETUID")

The same action can be performed using mbovalue implicit variable. The implicit variable mbovalue is an instance of MboValueAdapter class

mboValue = mbo.getMboValue("DESCRIPTION") 
currentValue = mboValue.getCurrentValue()
description = currentValue.asString()

The simplified form would be:

description = mbo.getMboValue("DESCRIPTION").getCurrentValue().asString()
priority = mbo.getMboValue("PRIORITY").getCurrentValue().asInt()
replaceCost = mbo.getMboValue("REPLACECOST").getCurrentValue().asDouble()
installDate = mbo.getMboValue("INSTALLDATE").getCurrentValue().asDate()
isRunning = mbo.getMboValue("ISRUNNING").getCurrentValue().asBoolean()
assetUID = mbo.getMboValue("ASSETUID").getCurrentValue().asLong()

Get previous value

To get the previous value of an attribute, the following must be done (only possible using the MboValueAdapter):

prevDesc = mbo.getMboValue("DESCRIPTION").getPreviousValue().asString()

Get initial value

To get the initial value of an attribute, the following must be done:

initialDesc = mbo.getMboValue("DESCRIPTION").getInitialValue().asString()

# getting value directly from the database
initialDesc = mbo.getDatabaseValue("DESCRIPTION")

Bonus Track

Get current date

To get the current date:

from psdi.server import MXServer
currentDate = MXServer.getMXServer().getDate()

Get internal value of a synonym

To get the internal value of a synonym domain:

mbo.getTranslator().toInternalString(<listname>, <externalValue>)
mbo.getTranslator().toInternalString(<listname>, <externalValue>, <mbo>)
mbo.getTranslator().toInternalString(<listname>, <externalValue>, <siteid>, <orgid>)

# mbo is an instance of LOCATIONS
loctype = mbo.getString("TYPE")
siteid = mbo.getString("SITEID")
orgid = mbo.getString("ORGID")

# In this case, the internal value is at System level
internalValue = mbo.getTranslator().toInternalString("LOCTYPE", mbo.getString("TYPE"))

# In this case, the internal value is at same level as the record
internalValue = mbo.getTranslator().toInternalString("LOCTYPE", loctype, mbo)

# In this case, the internal value is at Site level
internalValue = mbo.getTranslator().toInternalString("LOCTYPE", loctype, siteid, orgid)

# If the Mbo extends the StatefulMbo class (only for Status synonym domain)
# mbo can be an instance of ASSET, LOCATIONS, WORKORDER, SR, PO, etc
internalValue = mbo.getInternalStatus()

Get default external value of a synonym

To get the default external value of a synonym domain:

mbo.getTranslator().toExternalDefaultValue(<listname>, <internalValue>)
mbo.getTranslator().toExternalDefaultValue(<listname>, <internalValue>, <mbo>)
mbo.getTranslator().toExternalDefaultValue(<listname>, <internalValue>, <siteid>, <orgid>)

# mbo is an instance of ASSET
siteid = mbo.getString("SITEID")
orgid = mbo.getString("ORGID")

# In this case, the default external value is at System level
dfltExtValue = mbo.getTranslator().toExternalDefaultValue("LOCASSETSTATUS", "APPR")

# In this case, the default external value is at same level as the record
dfltExtValue = mbo.getTranslator().toExternalDefaultValue("LOCASSETSTATUS", "APPR", mbo)

# In this case, the default external value is at Site level
dfltExtValue  = mbo.getTranslator().toExternalDefaultValue("LOCASSETSTATUS", "APPR", siteid, orgid)

If you found my post interesting or useful and just want to say thanks, you can always buy me a coffee.

Leave a Reply