0

I'm trying to break this problem down into manageable parts: Spatial Query.


I want to create an automation script that will put a work order's LatitudeY coordinate in the work order's DESCRIPTION field.

I understand that a work order's coordinates are not stored in the WORKORDER table; they're stored in the WOSERVICEADDRESS table.

Therefore, I believe the script needs to reference a relationship in the Database Configuration application that will point to the related table.

How can I do this?

(Maximo 7.6.1.1)

User1974
  • 276
  • 1
  • 17
  • 63

2 Answers2

1

You can get the related Mbo and get the values from the related Mbo and use it as shown in the below code. By getting the related Mbo you can also alter it's attributes.

from psdi.mbo import MboConstants
serviceAddressSet = mbo.getMboSet("SERVICEADDRESS")
if(serviceAddressSet.count() > 0):
    serviceAddressMbo = serviceAddressSet.moveFirst()
    latitudeY = serviceAddressMbo.getString("LATITUDEY")
    longitudeX = serviceAddressMbo.getString("LONGITUDEX")
    mbo.setValue("DESCRIPTION","%s, %s" % (longitudeX, latitudeY),MboConstants.NOACCESSCHECK)
serviceAddressSet.close()
Swaroop
  • 105
  • 8
  • So a work order can have multiple service addresses? I don't think I was aware of this. – User1974 Aug 15 '19 at 06:18
  • 1
    No, work order will not have multiple service addresses. This approach can be used when you have multiple related Mbos. – Swaroop Aug 15 '19 at 08:03
0

I've got a sample script that compiles successfully:

from psdi.mbo import MboConstants
wonum = mbo.getString("WONUM")
mbo.setValue("DESCRIPTION",wonum,MboConstants.NOACCESSCHECK)

I can change it to get the LatitudeY value via the SERVICEADDRESS relationship:

from psdi.mbo import MboConstants
laty = mbo.getString("SERVICEADDRESS.LatitudeY")
longx = mbo.getString("SERVICEADDRESS.LONGITUDEX")
mbo.setValue("DESCRIPTION",laty + ", " + longx,MboConstants.NOACCESSCHECK)

This appears to work.

Swaroop
  • 105
  • 8
User1974
  • 276
  • 1
  • 17
  • 63
  • 1
    I suggest using a format string and parameters instead of just concatenating together a string. Since Maximo only has Python 2.5, that would look like `"%s, %s" % (laty, longx)`. In this case, it doesn't matter, but it would be good to get yourself in the practice of avoiding code-injection vulnerabilities. – Preacher Aug 12 '19 at 16:10
  • Thanks. Will do. On a related note: I've updated the question to say that I have Maximo 7.6.1.1. I notice that the [automation script window](https://i.stack.imgur.com/j1VgM.png) says that Python 2.7.0 is a supported language. Are you thinking that Maximo only has Python 2.5, or was that in older versions? – User1974 Aug 13 '19 at 12:56
  • 1
    Python 2.7 support is new with Maximo 7.6.1 and includes support for the `.format()` method on strings. [Read more](https://stackoverflow.com/questions/5082452/string-formatting-vs-format) on the similarities and differences between the `%` operator and the `.format()` method. – Preacher Aug 13 '19 at 14:03