Maximo Open Forum

 View Only
  • 1.  Rest API's and Database views

    Posted 09-15-2020 08:29
    Is it possible to retrieve data from a database view using a REST API?
    #Customizations

    ------------------------------
    Brian Swanson
    Herman Miller
    ------------------------------


  • 2.  RE: Rest API's and Database views

    Posted 09-15-2020 08:57
    Edited by Steven Shull 09-15-2020 08:59
    Yes, and how will depend on whether or not Maximo is aware of the view (IE is it configured as an object inside of Maximo). If it's an object inside of Maximo you should create an object structure to process it. If Maximo is not aware of the view, but the Maximo account has access to the database view, you can write an Automation Script and invoke that automation script from the REST API. Section 14 of the REST API document covers calling a script from the REST API pretty well. Overview (ibm.com)

    If you've never written an automation script to query the database, using DBShortcut is probably the easiest approach. If you call the script from the REST API, you'll have an implicit variable of request which you can call request.getUserInfo() to get their userInfo which is necessary to get their connection key. We typically use python and wrap this with a try except finally to ensure that the database connection is closed when we're done. I've written a really basic shell of the code to execute a database query, but you'll at least need to build the responseBody implicit variable to return back to your code. 

    from psdi.mbo import DBShortcut,SqlFormat

    try:
        dbShortcut=DBShortcut()
        dbShortcut.connect(request.getUserInfo().getConnectionKey())
        sqfQuery=SqlFormat("SELECT * FROM asset WHERE siteid=:1 and status='OPERATING'")
        sqfQuery.setObject(1,"ASSET","SITEID","BEDFORD")
        resultSet=dbShortcut.executeQuery(sqfQuery.format())

        while resultSet.next():
            resultSet.getString("ASSETNUM")
    except:
        # put your error handling here, whether that's emailing or what. Be careful that it won't generate another exception though
    finally:
        dbShortcut.close()


    Edited to try and fix formatting of the code. Using the code snippet is removing all the line breaks for me.

    ------------------------------
    Steven Shull
    Projetech
    ------------------------------



  • 3.  RE: Rest API's and Database views

    Posted 04-11-2022 07:41

    I have an object structure with parent object is XXX_VW which is view in maximo.

    Rest API post calling on this object structure is successfully creating data in table XXX_ABC on which this view is based on all child objects in OS.

    But now I am trying to create automation script object launch type on XXX_ABC but whenever REST Post on OS creates data this automation is not getting triggered. am I missing on anything ?



    ------------------------------
    Prashant B
    ------------------------------



  • 4.  RE: Rest API's and Database views

    Posted 04-11-2022 09:16
    Assuming I'm understanding correctly, this is working properly and the REST API aspect is irrelevant. Views are treated as separate objects from a Maximo event perspective (automation scripts, publish channels, data restrictions, etc.) because you may want different rules based on the object. For example, SRs, Incidents, & Problems are all views of TICKET. But what you need to capture on a SR can be very different than what you need to capture on an Incident.

    In scenarios where you want the same automation script logic to evaluate, you need to create an additional launch point on your other object. As long as it's a launch point based script (object, attribute, etc.) you can re-use the same script. In some of the special name based scripts (OBJECTNAME.NEW for example), then you need to create a second version of that script.

    ------------------------------
    Steven Shull
    IBM
    ------------------------------