Perhaps someone has a working example of posting a linked doc via a rest call to MAS.
I've tried this approach, it's creating the link, but when viewing the record and the linked docs, viewing the document fails with an error. We are not stuck with using this approach, it's just a best guess attempt. Other approaches are welcome.
Postman is posting to url
https://myserver/maximo/api/script/SERVICEREQUESTADD
the following json (note documentdata is a base64 encoded string)
{
"REPORTEDBY": "71311461F",
"REPORTEDBYID": "71311461F",
"REPORTEDEMAIL": "abc@def.com",
"REPORTEDPHONE": "1234567",
"DESCRIPTION": "Testing",
"DESCRIPTION_LONGDESCRIPTION": "long description",
"ASSETORGID": "EAGLENA",
"ASSETSITEID": "MYSITE",
"ORGID": "EAGLENA",
"SITEID": "MYSITE",
"LOCATION": "Z95",
"DOCLINKS": [
{
"DOCUMENT": "test.txt",
"DESCRIPTION": "File added by rest post",
"URLTYPE": "FILE",
"DOCTYPE": "Attachments",
"ADDINFO": "1",
"SHOW": "1",
"PRINTTHRULINK": "0",
"URLNAME": "test.txt",
"DOCUMENTDATA": "MTIzNHRlc3Qy"
}
]
}
******************************************************************************
And this is the SERVICEREQUESTADD script. As mentioned, the SR is created, the linked doc record is created, but the file cannot be viewed using the Maximo "View Linked Docs" UI feature.
# MAS 9 REST Automation Script
# Accepts JSON, creates SR, logs processing, returns SR number or error
from psdi.server import MXServer
from psdi.mbo import MboConstants
from java.util import Base64
from java.io import ByteArrayInputStream
from java.lang import Exception as JavaException
from com.ibm.json.java import JSONObject, JSONArray
mxServer = MXServer.getMXServer()
responseBody = "{}"
try:
service.log_info("CREATE_SR_REST: Script execution started")
if not requestBody:
service.log_info("CREATE_SR_REST: No JSON payload received")
raise Exception("No JSON payload provided")
service.log_info("CREATE_SR_REST: Raw requestBody = " + str(requestBody))
data = JSONObject.parse(requestBody)
service.log_info("CREATE_SR_REST: JSON parsed successfully using IBM JSONObject")
userInfo = mxServer.getSystemUserInfo()
srSet = mxServer.getMboSet("SR", userInfo)
sr = srSet.add()
service.log_info("CREATE_SR_REST: SR MBO created")
fields = [
""REPORTEDBY","REPORTEDBYID","REPORTEDEMAIL","REPORTEDPHONE",
"DESCRIPTION","DESCRIPTION_LONGDESCRIPTION","AFFECTEDPERSON",
"AFFECTEDPERSONID","ASSETORGID","ASSETSITEID",
"ORGID","SITEID","LOCATION"
]
for f in fields:
if data.containsKey(f):
val = data[f]
if val is not None and str(val) != "":
sr.setValue(f, str(val), 11)
# ---------------------------------------------------------------------
# Process Attachments
# ---------------------------------------------------------------------
if data.containsKey("DOCLINKS"):
docSet = sr.getMboSet("DOCLINKS")
docArray = data.get("DOCLINKS")
for d in docArray:
filename = d.get("DOCUMENT")
description = d.get("DESCRIPTION")
filedata = d.get("DOCUMENTDATA")
service.log_info(">>> Attaching file: " + filename)
# Decode Base64
bytesData = Base64.getDecoder().decode(filedata)
#stream = ByteArrayInputStream(bytesData)
document = d.get("DOCUMENT")
description = d.get("DESCRIPTION")
urltype = d.get("URLTYPE")
doctype = d.get("DOCTYPE")
urlname = d.get("URLNAME")
filedata = d.get("DOCUMENTDATA")
service.log_info(">>> Processing attachment: " + document)
doc = docSet.add()
doc.setValue("ADDINFO",1)
doc.setValue("DOCUMENT", document)
doc.setValue("DESCRIPTION", description)
doc.setValue("URLTYPE", urltype)
doc.setValue("DOCTYPE", doctype)
doc.setValue("URLNAME", urlname)
doc.setValue("NEWURLNAME", urlname)
doc.setValue("DOCUMENTDATA", filedata)
service.log_info("Saving SR " + sr.getString("TICKETID"))
srSet.save()
sr_num = sr.getString("TICKETID")
service.log_info("CREATE_SR_REST: SR saved successfully: " + sr_num)
responseBody = (
'{"status":"SUCCESS","sr_number":"' + sr_num + '"}'
)
except JavaException as je:
msg = str(je)
service.log_info("CREATE_SR_REST: JavaException occurred: " + msg)
responseBody = '{"status":"ERROR","message":"' + msg + '"}'
except Exception as e:
msg = str(e)
service.log_info("CREATE_SR_REST: Exception occurred: " + msg)
responseBody = '{"status":"ERROR","message":"' + msg + '"}'
service.log_info("CREATE_SR_REST: Script completed")
#Integrations#MaximoApplicationSuite------------------------------
Jose Nodeland
JedaWorks
------------------------------