Maximo

 View Only
  • 1.  how to read the JSON data through automation script (user exit automation script)

    Posted Wed January 24, 2024 05:35 AM

    Hi All - Currently I am developing one custom API where I can get the data from external system and I mapped that value to with a maximo existing attribute using JSON mapping. Could any one please tell me how to read the JSON data through automation script (user exit automation script)

    Regards,

    Biswa



    ------------------------------
    Biswaranjan Mishra
    ------------------------------


  • 2.  RE: how to read the JSON data through automation script (user exit automation script)

    IBM Champion
    Posted Wed January 24, 2024 06:10 PM

    Hi @Biswaranjan Mishra,

    I'm unsure if I understood what you're trying to do, but here is how to get a JSON object on automation scripts.

    In my example, I used it on an OSIN autoscript. You can find more details at https://ibm-maximo-dev.github.io/maximo-autoscript-documentation/integration/integrationevents/.

    from com.ibm.json.java import JSONObject
    
    # for debugging purposes
    logger = MXLoggerFactory.getLogger("maximo.autoscript")
    
    logger.debug("==================== OSIN: START =====================")
    userInfo = MXServer.getMXServer().getSystemUserInfo()
    
    payload = JSONObject.parse(str(ctx.getData()));
    
    # to access a JSON property value, you can do
    logger.debug("JSON value:" + str(payload["property"]))
    
    # looping on arrays - e.g. asset specifications
    assetSpecSet = payload['assetspec']
    for spec in assetSpecSet:
        # test if property "exists"
        if 'assetattrid' in spec:
            logger.debug("ASSETATTRID: " + str(spec['assetattrid']))
    

    I hope it can help you.

    Cheers.



    ------------------------------
    Maycon Belfort
    Consultant
    BPD Zenith
    Melbourne
    Australia
    ------------------------------



  • 3.  RE: how to read the JSON data through automation script (user exit automation script)

    Posted Thu January 25, 2024 06:51 AM

    Thanks Maycon for reply.  

    In our case we are getting COMPVALUE values from external system and it contains maximum 20 characters. we need to build the below rules, could you please help me on this.

    e.g. if COMPVALUE = '000252A100'

    ·         The value of the first component is '0000' followed by the first three characters of the <COMPVALUE>.

    ·         The value of the second component is the next four characters of the <COMPVALUE> (positions 4 to 7).

    ·         The value of the third component is the next three characters of the <COMPVALUE> (positions 8 to 10).

    ·         The value of the fourth component is the next three characters of the <COMPVALUE> (positions 11 to 13).

    ·         The value of the fifth component is the next three characters of the <COMPVALUE> (positions 14 to 16).

    ·         The value of the 6th component is the next three characters of the <COMPVALUE> (positions 17 to 19).

    Regards,

    Biswa



    ------------------------------
    Biswaranjan Mishra
    ------------------------------



  • 4.  RE: how to read the JSON data through automation script (user exit automation script)

    Posted Tue January 30, 2024 03:42 PM

    In your case I think, just use ctx.getData("COMPVALUE") and use substring function to breakdown the value to a string array and use them to your business logic



    ------------------------------
    Salah Thandalam Valappil Hassan
    Consultant
    Infosys
    ------------------------------



  • 5.  RE: how to read the JSON data through automation script (user exit automation script)

    Posted Mon February 05, 2024 07:48 AM
    Edited by Sankar Ganesh Mon February 05, 2024 07:59 AM

    There are different functions you may use at each level of inbound,outbound processing. 
    Inbound: Context APIs for the inbound processing of object structures - IBM Documentation
    Outbound: Functions for outbound processing of object structures - IBM Documentation

    For your requirement, below code can work.

    #(written in python)

    compValue=str(ctx.getMbo().getString("<COMPVALUE>"));

    firstComp='0000'+compValue[0:3]
    secondComp=str(compValue[3:7])
    thirdComp=compValue[7:11]
    fourthComp=compValue[11:15]


    If it is inbound:
    struc = ctx.getData();
    compValue= str(struc.getCurrentData("<COMPVALUE>"));

    ------------------------------
    Sankar Ganesh
    ------------------------------



  • 6.  RE: how to read the JSON data through automation script (user exit automation script)

    Posted Sun February 25, 2024 11:10 PM
    Define a JSON parser in automation script using native Java hashmap libraries. Call the API endpoint of the service and map the response bytes with MBO and external data. 
    You may need to import the security certificate of the API endpoints though to ensure Maximo establishes the connection with the API end point.

    Here is one example where I read the JSON data of Work order from an external system ( tasknum, district, eqtag, station) and mapped it with WO MBO fields.

    I hope this helps


    responseBytes = handler.invoke(map,None)
    response = String(responseBytes,"utf-8")
    # raise TypeError(response)
    object = JSONObject.parse(response)
    message = object.get('message')
    data = object.get('data')
    if(message.get('code') == 0):
     if(data is not None):
      mbo.setValue("WONUM",str(data.get("tasknum")),11L)
      mbo.setValue("SITEID",str(data.get("district")),11L)
      mbo.setValue("ASSETNUM",str(data.get("eqtag")),11L)
      mbo.setValue("LOCATION",str(data.get("station")),11L)
      #mbo.getThisMboSet().save()

    Thanks
    Kushal
    'The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com'

    Internal - General Use






  • 7.  RE: how to read the JSON data through automation script (user exit automation script)

    Posted Tue April 23, 2024 03:04 AM

    Hi Biswaranjan

    For using external system you can reference to the link https://ibm-maximo-dev.github.io/maximo-autoscript-documentation/integration/enterpriseevents 

    to read origina data, it using OslcUtils from com.ibm.tivoli.maximo.oslc

     to read the value from JSON, using erData.getCurrentData("ORIG_KEY")

     to update the value pass to maximo, using irData.setCurrentData("MaximoAttribute", "VALUE")

    Regards,

    Jason



    ------------------------------
    Jason Pun
    Technical Consulant
    ------------------------------