I fully agree with Steven. What you need to do is find out why it's read-only.
The first thing to do is to check the history flag, which can be set by canceling or closing the work order.
If that flag is cleared, then you check the status. Use the WOSTATUS synonym domain to convert your WO's status to its internal value. Then go to the Organizations application and see whether the edit settings for work orders for that organization allow the asset to be changed during that internal status.
If the last two checks tell you that your work order's asset should be allowed to change, then you have probably made some business rules of your own that aren't being satisfied. So, you need to go check out the Global Data Restrictions in the Security Groups app, and check out security group specific data restrictions that apply to your user. And, if you still can't figure it out, go look at your object or attribute launch points and their automation scripts.
Someone mentioned the UI, but you're hitting a script via the REST API, so the UI (beans, lookups, etc) are not applicable.
On a slightly different note, I strongly suggest you look at the Maximo 7.6.0.9 JavaDocs which you can get to from the
Maximo APIs and SDKs page. In particular, you can find the different setValue() methods on psdi.mbo.Mbo and the psdi.mbo.MboConstants class which has the flags that Biplab and Steven referred to.
------------------------------
Blessings,
Jason Uppenborn
Sr. Technical Maximo Consultant
Ontracks Consulting
------------------------------
Original Message:
Sent: Mon June 29, 2020 08:13 AM
From: Steven Shull
Subject: Change WO's ASSETNUM via autoscript?
Strongly second Kevin's response. If the field is read-only the work order is in a status that doesn't allow the asset to be changed. Maximo has the concept of edit rules (configured in the Organization application) which control when certain attributes (such as Asset) are allowed to be modified on a WO. These rules are evaluated both interactively in the UI and through any background process (automation script/cron task/escalation). These can be adjusted if necessary, but out of box only allow it to be modified in a WAPPR status.
There are a couple of reasons for this. If a technician has done work on asset 1 and you change the work order to asset 2, that means work was done on the wrong asset. Someone reviewing it after the fact will think maintenance was done on the proper asset but it might never have been. In those cases it tends to be better to create a new work order rather than change the asset. Another one most aren't aware of is if you recorded any actuals, these costs won't be properly rolled up to the asset costs if the asset is changed after they're recorded. These transactions record the asset at the time of the transaction and then when the roll up occurs it matches that asset to the work order asset and if it doesn't match, it gets ignored.
If you decide you need to allow these adjustments, I would recommend trying to use 2L (or MboConstants.NOACCESSCHECK if you import MboConstants from psdi.mbo) over 11L. Suppressing validation & action eliminate quite a few checks that you would want to occur. NOACCESSCHECK ignores the read-only aspect, but otherwise all other logic is evaluated.
------------------------------
Steven Shull
Director of Development
Projetech Inc
Cincinnati OH
Original Message:
Sent: Mon June 29, 2020 03:40 AM
From: Kevin Elliott
Subject: Change WO's ASSETNUM via autoscript?
Hi
My first advice is stick to OOTB - Maximo is designed for good reason! What is the unique business requirement that is demanding changing the WO asset number by not following the OOTB ?
------------------------------
Kevin Elliott
Original Message:
Sent: Sat June 27, 2020 11:02 AM
From: Biplab Choudhury
Subject: Change WO's ASSETNUM via autoscript?
Hi ,
11L signifies the MboConstants value.
MboConstant is an Interface which is commonly used to Suppress field methods .
Below url gives details about use of mboconstants.
http://maximowave.blogspot.com/2012/10/mbo-constants-in-maximo.html
In your case, 11L - Suppress field Validaton, Action and Access check.
Asset field must be set as readonly on the UI therefore you were getting an error earlier but with the use of 11L, readonly is supressed and thus you are not getting the error.
------------------------------
Biplab Choudhury
Maximo Consultant
Tata Consultancy Services
Melbourne
Original Message:
Sent: Fri June 26, 2020 04:10 PM
From: User1971
Subject: Change WO's ASSETNUM via autoscript?
This seems to work, although I have no idea why.
woMbo.setValue("assetnum", assetnum, 11L)
------------------------------
Thanks
Original Message:
Sent: Fri June 26, 2020 03:16 PM
From: User1971
Subject: Change WO's ASSETNUM via autoscript?
I'm attempting to change a WO's ASSETNUM via an automation script (Maximo 7.6.1.1).
The specific line I'm trying to use is:
woMbo.setValue("assetnum", assetnum)
But I'm getting an error that says I can't edit the asset field:
{"oslc:Error":{"oslc:statusCode":"400","errorattrname":"assetnum","spi:reasonCode":"BMXAA0019I","correlationid":null,"oslc:message":"BMXAA0019I - The Asset field is either read only or part of the primary key. You cannot edit this field.","oslc:extendedError":{"oslc:moreInfo":{"rdf:resource":"http:\/\/vsMAXAPSB.city.oshawa.on.local\/maximo\/oslc\/error\/messages\/BMXAA0019I"}}}}
Is there a way to edit the ASSETNUM in a workorder via an automation script?
Full script: UPDATEWOASSETNUM
#URL:
#http://vsmaxapsb:9080/maximo/oslc/script/UPDATEWOASSETNUM?_lid=wilson&_lpwd=wilson&wonum=LWO0280&assetnum=LA1234
#
from psdi.server import MXServer
from psdi.mbo import MboSet
from psdi.mbo import MboConstants
resp = {}
wonum = request.getQueryParam("wonum")
assetnum = request.getQueryParam("assetnum")
woset = MXServer.getMXServer().getMboSet("workorder",request.getUserInfo())
whereClause = "wonum= '" + wonum + "'"
woset.setWhere(whereClause)
woset.reset()
woMbo = woset.moveFirst()
#If workorder already exists, update it:
if woMbo is not None:
woMbo.setValue("assetnum", assetnum)
woset.save()
woset.clear()
woset.close()
resp[0]='Updated workorder ' + wonum
responseBody =resp[0]
------------------------------
Thanks
------------------------------
#Maximo
#AssetandFacilitiesManagement