Maximo Open Forum

 View Only

 Retrieving linked docs via autoscript

  • Customizations
  • Integrations
Jose Nodeland's profile image
Jose Nodeland posted 11-20-2023 16:39

I'm trying to send any linked documents on a Maximo record to an external system, via a Maximo 7611 autoscript.  The document has to be sent as a Base64 encoded string.

I've configured Maximo as per

Downloading attachments based on doctypes using API

Downloading attachments based on doctypes using API

Ibm remove preview
Downloading attachments based on doctypes using API
This document covers the steps to download attachments based on doctypes
View this on Ibm >

And can retrieve linked docs using Postman, with the following url

https://max761.edu/maximo/api/os/mxapidoclinks?oslc.where=ownertable="ASSET"and ownerid=45&oslc.select=description,urltype,urlname,documentdata&inlinedoc=1&oslc.pagesize=100

So far so good, the linked docs are returned in the Postman response as a base 64 string.  But I want to retrieve the linked docs in a Maximo autoscript, as the doc has to be sent to an external system.  I cannot get the autoscript to work.  Autoscript is attached to this post.

------------------------------------------------------------------------------

When calling the Autoscript via Postman, or via Maximo, the following is received.  Can anyone see what I am doing wrong in the Autoscript?  This is what the autoscript is sending to the log file.

20 Nov 2023 15:28:07:852 [INFO] *** GETLINKEDDOCS start
20 Nov 2023 15:28:07:852 [INFO] calling https://max761.edu/maximo/api/os/mxapidoclinks?oslc.where=ownertable="ASSET"and ownerid=45&oslc.select=description,urltype,urlname,documentdata&inlinedoc=1&oslc.pagesize=100
20 Nov 2023 15:28:07:915 [INFO] validating response code: 400
20 Nov 2023 15:28:07:915 [INFO] Error Response Code: 400
20 Nov 2023 15:28:07:915 [INFO] Response Data: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>IBM_HTTP_Server Server at max761duisdi1.uchicago.edu Port 443</address>
</body></html>
20 Nov 2023 15:28:07:915 [INFO] *** GETLINKEDDOCS endd

Maycon Belfort's profile image
Maycon Belfort

Hi Jose,

Maybe it's a silly question, but why are you trying to get the attachment with an automation script if you need to send it to an external system?

Why not create an Object Structure with the main table Asset and the Doclinks tables, an External System, and a Publish Channel? Using OOTB MIF, you can send the attachment using the non-persistent field DOCUMENTDATA from the DOCLINKS object in your OS.

If you need to send it as JSON, you can use the JSON Mapping Application to convert it to a JSON structure that your external system will understand.

It can only be configurations, and you won't need any Automation Script. If you really need to use a script, I think you can still use the same DOCUMENTDATA field to get the base64 encoded attachment from the MBO without calling Maximo's API by using mbo.getString("DOCUMENTDATA") if your main MBO is the DOCLINKS table or getting the MBOSet from ASSET to DOCKLINKS.

Jose Nodeland's profile image
Jose Nodeland

The reason for using the autoscript is there is an existing script that creates and sends the json message, and now they want linked docs attached to the message.  So I'm trying to develope the "get linked docs" in a seperate script, which I will integrate into, or call from, the original script.

I'm not sure what you mean by " I think you can still use the same DOCUMENTDATA field to get the base64 encoded attachment from the MBO without calling Maximo's API by using mbo.getString("DOCUMENTDATA") ".  So just to try something I made a script with "mboset = MXServer.getMXServer().getMboSet("MXAPIDOCLINKS", MXServer.getMXServer().getSystemUserInfo())", but it errors out as suspected, with ""oslc:message": "BMXAA4216E - Unknown Object named MXAPIDOCLINKS has been encountered.".

Can you explain further, I did not realize it's possible to call an Object Structure as an mbo.

Maycon Belfort's profile image
Maycon Belfort

Hi Jose,

If your script is for object WORKORDER, your MBO is the open work order. So getting the DOCLINKS relationship, you'll get all attachments, and for each of them, you can get the DOCUMENTDATA field.

For instance:

doclinksMboSet = mbo.getMboSet("DOCLINKS")

if not doclinksMboSet.isEmpty():
     doclinkMbo = doclinksMboSet.moveFirst()
     if doclinkMbo is not None:
         doclinkData = doclinkMbo.getString("DOCUMENTDATA")
         service.log_error("DOCUMENTDATA: %s" % doclinkData) 
         // create the JSON to send the DOCUMENTDATA

If you can confirm that you have the base64 encoded value from this DOCUMENTDATA field, you can use it to send the JSON with the doclink file.

Jose Nodeland's profile image
Jose Nodeland

Unfortunately it appears the documentdata attribute is not populated.  The call getString("DOCUMENTDATA") did not throw an error, so it recognizes the attribute.

            doclinksMboSet = mbo.getMboSet("DOCLINKS")
            if not doclinksMboSet.isEmpty():
                doclinkMbo = doclinksMboSet.moveFirst()
                if doclinkMbo is not None:
                    doclinkData = doclinkMbo.getString("DOCUMENTDATA")
                    log("DOCUMENTDATA = " + doclinkData)                    
                    log("DOCUMENT = " +  doclinkMbo.getString("DOCUMENT"))
                    log("WebUrl = " +  doclinkMbo.getString("WebUrl"))

Which logged the following.  But maybe I can do something with the WebUrl.

22 Nov 2023 18:55:01:703 [INFO] *** GETLINKEDDOCS start
22 Nov 2023 18:55:01:710 [INFO] DOCUMENTDATA = 
22 Nov 2023 18:55:01:711 [INFO] DOCUMENT = PMCRONTASK
22 Nov 2023 18:55:01:711 [INFO] WebUrl = https://max761.edu/ATTACHMENTS/pmcrontask.jpg
22 Nov 2023 18:55:01:711 [INFO] *** GETLINKEDDOCS end