Charles
Charles

Reputation: 29

Maximo automatisation script to change statut of workorder

I have created a non-persistent attribute in my WoActivity table named VDS_COMPLETE. it is a bool that get changed by a checkbox in one of my application.

I am trying to make a automatisation script in Python to change the status of every task a work order that have been check when I save the WorkOrder.

I don't know why it isn't working but I'm pretty sure I'm close to the answer... Do you have an idea why it isn't working? I know that I have code in comments, I have done a few experimentations...

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

mxServer = MXServer.getMXServer()
userInfo = mxServer.getUserInfo(user)

mboSet = mxServer.getMboSet("WORKORDER")
#where1 = "wonum = :wonum"
#mboSet .setWhere(where1)

#mboSet.reset()

workorderSet = mboSet.getMbo(0).getMboSet("WOACTIVITY", "STATUS NOT IN ('FERME' , 'ANNULE' , 'COMPLETE' , 'ATTDOC')")
#where2 = "STATUS NOT IN ('FERME' , 'ANNULE' , 'COMPLETE' , 'ATTDOC')"
#workorderSet.setWhere(where2)


if workorderSet.count() > 0:
    for x in range(0,workorderSet.count()):
        if workorderSet.getString("VDS_COMPLETE") == 1:
            workorder = workorderSet.getMbo(x)
            workorder.changeStatus("COMPLETE",MXServer.getMXServer().getDate(), u"Script d'automatisation", MboConstants.NOACCESSCHECK)

workorderSet.save()
workorderSet.close()

Upvotes: 0

Views: 4440

Answers (1)

Dex
Dex

Reputation: 1271

It looks like your two biggest mistakes here are 1. trying to get your boolean field (VDS_COMPLETE) off the set (meaning off of the collection of records, like the whole table) instead of off of the MBO (meaning an actual record, one entry in the table) and 2. getting your set of data fresh from the database (via that MXServer call) which means using the previously saved data instead of getting your data set from the screen where the pending changes have actually been made (and remember that non-persistent fields do not get saved to the database).

There are some other problems with this script too, like your use of "count()" in your for loop (or even more than once at all) which is an expensive operation, and the way you are currently (though this may be a result of your debugging) not filtering the work order set before grabbing the first work order (meaning you get a random work order from the table) and then doing a dynamic relationship off of that record (instead of using a normal relationship or skipping the relationship altogether and using just a "where" clause), even though that relationship likely already exists.

Here is a Stack Overflow describing in more detail about relationships and "where" clauses in Maximo: Describe relationship in maximo 7.5

This question also has some more information about getting data from the screen versus new from the database: Adding a new row to another table using java in Maximo

Upvotes: 1

Related Questions