Thanks again to Steven and Jason for your input.
I plan to pursue the OOB box option that you mentioned: "Create a WO using an object structure" ...aka... "MXWO integration object".
On a side note, I did end up pursuing the custom script option, just as a professional development exercise. It was a relatively simple example where I could learn a bit about automation scripting.
Again, I'm planning to switch to the OOB method, but for now, here's the code I came up with:
I would be happy to hear about any flaws in the script -- or improvements that could be made (knowing full-well that this is not the preferred method).
from psdi.mbo import SqlFormat
from psdi.server import MXServer
from psdi.mbo import MboSet
IGNORE_RULES = 2L
paramdict = {
p[2:]: request.getQueryParam(p)
for p in request.getQueryParams()
if p.startswith('f_')
}
woset = MXServer.getMXServer().getMboSet("workorder",request.getUserInfo())
try:
sqf = SqlFormat("wonum=:1")
sqf.setObject(1,"WORKORDER","WONUM",request.getQueryParam("f_wonum"))
woset.setWhere(sqf.format())
woset.reset()
woMbo = woset.moveFirst()
if woMbo is None:
woMbo=woset.add()
verb = 'Created'
else:
verb = 'Updated'
for k,v in paramdict.items():
woMbo.setValue(k,v,IGNORE_RULES)
resp = verb + ' workorder ' + request.getQueryParam("f_wonum")
woset.save()
woset.clear()
finally:
woset.close()
responseBody = resp
Some context about ignoring the rules via
2L can be found here:
Change WO's ASSETNUM via autoscript?
Original Message:
Sent: Wed June 17, 2020 10:50 AM
From: Jason VenHuizen
Subject: Invoke autoscript via URL to create WO
So there are a few ways you could tackle this, but the simplest by far is to just use the out of the box MXWO integration object. Making a POST request to the server at
http://server.name.here/maximo/oslc/os/MXWO
with a JSON of
{ "wonum": "54321", "description": "Demo Work Order", "siteid": "BEDFORD"}
Will create a new work order with the specified work order number. Be aware that it is your responsibility to check that that work order number has not been used previously otherwise you will get the following error.
BMXAA4129E - The record for Site=BEDFORD, Work Order=54321 already exists. Ensure that the key value for the given record is unique.
If you have custom logic you want to apply you can do so using the integration pipeline Automation Scripts.
You can do what Steven suggested, but note that he is using the getSystemUserInfo()
method to get the system user to create the work order, which means that your work order will be created as the system user and not the actual user that is performing the action. This may impact other conditional expression behavior and bypass any security constraints you have in place.
Also, since the system user never logs out you need to be very careful to close any MboSets opened by that user otherwise they will stay in memory until server restarts, in other words you will create a memory leak.
------------------------------
Jason VenHuizen
Original Message:
Sent: Tue June 16, 2020 07:51 PM
From: User1971
Subject: Invoke autoscript via URL to create WO
I have a URL that invokes a Jython automation script (related post here):
http://server:host/maximo/oslc/script/CREATEWO?_lid=wilson&_lpwd=wilson&v_WONUM=LWO0001
The script is called CREATEWO (it does not have any launch points or bind variables):
resp = {};
v_WONUM = request.getQueryParam("v_WONUM")
responseBody="Here's some fake text about WO: " + v_WONUM + " from the Maximo automation script."
The script runs successfully; it takes in the WONUM and passes back a message.
Question:
I want to enhance the script so that it creates a new WO in Maximo using the WONUM that was passed in.
Is it possible to do this?
------------------------------
Thanks
------------------------------
#Maximo
#AssetandFacilitiesManagement