Bulk upload images via Integration Framework



In the previous post, I have provided an example on how we can customize Object Structure to enable import/export binary data via MIF. In Maximo 7.6, the automation scripting framework has been greatly extended to support integration. With this update, we can enable import/export of binary data by adding a simple script without having to write and deploy custom java code. Below is an example how we can configure Maximo 7.6 to bulk upload images to Item Master application:

Step 1: Add an Object Structure integration script
  • Open System Configuration > Platform Configuration > Automation Script application
  • On Select Action menu, choose Create > Script for Integration
  • On the Create Script for Integration pop-up, enter the following details:
    • Select “Object Structure
    • Choose “MXITEM” for Object Structure
    • Select “Inbound Processing
    • Language: Python
    • Paste the following piece of code to the  Source Code text area:


    • Click on Create. Then save the script


Step 2: Modify MXItem object structure to include IMGLIB table
  • Open Integration > Object Structures application
  • Open MXITEM object structure
  • Under “Source Object for MXITEM”, click New Row, then enter the following details:
    • Object: IMGLIB
    • Parent Object: ITEM
    • Relationship: IMGLIB
  • Save the script


Step 3: Upload images to Item Master

I have written a sample Excel VBA tool to bulk upload images to Item Master which you can download using this GitHub repo.

You can use the application Import/Export feature or MxLoader tool to do the same. However, if you use these tools, you will need a separate tool to encode image files to Base64 encoded text string. There are many of such tools available online or as offline downloads. Or you can just use part of the code I provided in the example to do the encoding, then combine with MxLoader to achieve what you want.

Note: beware of photos taken from newer cameras, the files usually have high resolution and thus can be quite big. I’ve seen an eager team of engineers uploaded images for all assets and inventory items in a power plant, and overnight, the database grew from 1GB to 20GB. Thus make sure you resize the images before uploading. One quick and simple method in Windows is to select multiple files, then right-click, choose Send To > Mail Recipient. Windows will give you a pop-up to resize the files, choose the smallest size (640x480). Windows will resize the files, then attach it to Outlook, in Outlook, select all the files, and copy/paste them to a different folder. These files will be much smaller than original full resolution files.



Update (Jul/2020): Someone reported that when he followed this instruction, data in the Item/Organisation Details table was removed. It is because the modification of an existing out-of-the-box Object Structure in Step 2 is a bad practice. I used it for simplicity. On Production, we should always create a new object structure and include only the tables we need. To fix it, try creating a new OS as follows:

Create a new OS: MXLITEM

- Create an Integration Script as mentioned in Step 1 above, but for the new object MXLITEM instead
- Use version 2 of the sample Excel file I uploaded to the same GitHub repo

18 comments:

  1. Yes this is good solution. I have come across a similar requirement but we need to handle this in a user exit those days. Thanks to Automation script for integration nowadays.

    ReplyDelete
    Replies
    1. The best thing about this is we don't have to deploy custom java code. Like for this imglib upload use-case, everything can be done online without server restart or access to the server or database. So that's awesome.

      Delete
  2. It is a fast-approach solution. I am able to upload bulk images.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hi Viet , do you suggest how to get data bean or app bean instance in an automation script with action launch point ?
    can we get client session details ?

    ReplyDelete
  5. Hi. In my case the excel works OK but when I go to the item in Maximo the image shows a broken or corrupted image icon (the torn picture icon). If I go to the upload image action I can see the name of the file showing correctly. What am I doing wrong?

    ReplyDelete
    Replies
    1. It is likely that the Automation Script doesn't run, thus, the encoded JPEG data has not been decoded before saving to the table. Could it be Admin Mode is on? Or perhaps Autoscript was created against the wrong Object Structure?

      Delete
  6. Viet,
    I am trying to use a jython script to change the default image in maximo for an asset to one selected from the attachments for the asset. Here is part of the code (I referred to your code as an example):

    urlName='//maximoattachments.mycompany.org/maximoattachmentstorage/DEV/DOCLINKS/ATTACHMENTS/goldstar.jpg'
    ...
    file_object = open(urlName, 'rb')
    all_the_data = file_object.read()
    ...
    assetImg.setValue("IMAGE",Base64.decode(all_the_data), MboConstants.NOACCESSCHECK)

    I was expecting a jpg header in the IMGLIG of 0xFFD8FFE1 but it stored 0x13189F30

    Any Ideas?

    ReplyDelete
  7. Nice trick to reduce image size!

    Regards

    ReplyDelete
  8. Nice article , Viet do you know how to get details from error'ed message from message-traking and manipulate the message using the automation script and process the same to fix error.

    ReplyDelete
  9. Yes is a very good solution to upload images in mass/bulk way.

    ReplyDelete
  10. It is working fine & good solution.Thanks for great information.

    ReplyDelete
  11. I have a requirment where i need to download attachments using REST API ..is it possible?

    Please share the solution

    ReplyDelete
  12. Hi, which folders should we placed the image file?

    Thanks

    ReplyDelete
  13. Veit,

    What do I need to add to the VBA Script to be able to upload Image to the Asset Record. I am getting a error related to SiteID

    ReplyDelete
  14. Hi Viet,
    This is really a very good solution.
    Do you have similar thing for Asset as well?

    ReplyDelete
    Replies
    1. I don't have it ready available. But you can tweak the same provided example code to upload Imglib for Asset table.

      Delete