Maximo

 View Only
  • 1.  Getting error in reading external json in automation script for external service

    Posted Tue June 21, 2022 10:12 AM
    Pls help in resolving this issue.
    In the external exit automation script for enterprise service when trying to read the external json payload I am getting below error
    Error 500: AttributeError: type object 'com.ibm.tivoli.maximo.oslc.OslcUtils' has no attribute
    'byteToJson' in <script> at line number 2

    Below is code to read the external json data.

    from com.ibm.tivoli.maximo.oslc import OslcUtils
    jsonData = OslcUtils.byteToJson(erData.getOriginalByteData())

    Is there any alternate syntax to parse json and read it. Let me know if additional info required.

    Maximo version is - Tivoli's process automation engine 7.6.1.2-IFIX20220330-1115 Build 20200715-0100

    ------------------------------
    Abhinav Srivastava
    ------------------------------



    #MaximoIntegrationandScripting
    #Maximo
    #AssetandFacilitiesManagement


  • 2.  RE: Getting error in reading external json in automation script for external service

    Posted Wed June 22, 2022 08:09 AM
    I'm assuming you were the one working with Tom Sarasin yesterday? I'm sorry about our documentation mistake. I submitted a PR yesterday to get it fixed.

    In case someone else stumbles on this post, the correct method to use is

    jsonData = OslcUtils.bytesToJSONObject(erData.getOriginalByteData())

    ------------------------------
    Steven Shull
    ------------------------------



  • 3.  RE: Getting error in reading external json in automation script for external service

    Posted Thu June 23, 2022 03:49 AM
    Thanks Steven, the issue is sorted now.
    Anamitra suggested to use the method - OslcUtils.bytesToJSON(erData.getOriginalByteData()) which is working as well. How is this different from what you suggested -  OslcUtils.bytesToJSONObject(erData.getOriginalByteData())

    ------------------------------
    Abhinav Srivastava
    ------------------------------



  • 4.  RE: Getting error in reading external json in automation script for external service

    Posted Thu June 23, 2022 08:55 AM

    bytesToJSON utilizes the JSONArtifact interface which is an interface the JSONArray & JSONObject utilize. That means you could get back an array or an object from the code. If you want something that will work no matter what the JSON data looks like then the bytesToJSON is the thing to choose. 

    How you interact with the data is different if you have a JSONArray or a JSONObject. If you know what you should have and want to be explicit on what you want back, you can utilize:

    bytesToJSONArray & bytesToJSONObject

    These utilize the same bytesToJSON and then verifies whether they are type expected (JSONArray or JSONObject) and will throw an error if the data isn't in Array or Object format respectively. 


    In this scenario of utilizing an Enterprise Service, I don't think it really matters either way. erData I believe will always be a single record (not an array). At that point you'd always get a JSONObject back so it wouldn't impact your script processing. 



    ------------------------------
    Steven Shull
    ------------------------------