With the introduction of the Maximo Application Suite, I have had to deal with more and more Maximo environments on the cloud. This often means there is no access to the backend such as the database or the Websphere/Openshift console. Sometimes, to troubleshoot issues, it is critical to be able to run queries on the database. In this post, I will introduce a new approach to accessing the database using Automation Script.
From Maximo version 7.6.0.9, we can now build custom API using automation script. This is a powerful new feature yet it looks to be underutilized by the community.
The first obvious use case is it gives us the freedom to build any API we want without being restricted by the limitations of the Maximo Integration Framework. For example, we can create an API that returns data in CSV or binary format. Or we can use it to upload data and bypass the business layer.
Since it allows us to use the browser to interact with Automation Script, and the script framework has access to all Java functions of the MBO layer, We can exploit it to execute all sorts of weird operations.
https://[MAXIMO_ROOT]/maximo/oslc/script/[SCRIPT_NAME]
In an article I posted a few days ago, I used API script to call a Java function to refresh Maximo sequence and avoid a restart. Using the same approach, we can do a database configuration and deployment without downtime.
In this post, I’ll demonstrate how we can use API script to run SELECT, UPDATE, DELETE SQL statements to Maximo database without direct DB access. This can come in handy when DB access is restricted. Of course, we can use MXLoader to achieve the same result. However, this method is a lot more convenient.
Creating an API script is very simple, we just need to create a script without a launch point. Then we can call it by accessing this URL on the browser:
If you’re already logged in and have a session. That is all it takes. Otherwise, to authenticate the request, you can pass in username and password parameters like you normally do when calling the REST API.
https://[MAXIMO_ROOT]/maximo/oslc/script/[SCRIPT_NAME]?_lid=[USERNAME]&_lpwd=[PASSWORD]
To run a SELECT query on the database, I created a script named RUNSQL with the code below:
To use the script to run a query, I typed the SQL query directly in the URL in theĀ sql parameter as below.
https://[MAXIMO_URL]/maximo/oslc/script/runsql?method=SELECT&sql=SELECT top 10 assetnum,description,status FROM asset WHERE status = 'OPERATING'
In this case, the data is returned to the browser in the CSV format.
To execute a query that does not return data (INSERT/UPDATE/DELETE):
https://[MAXIMO_URL]/maximo/oslc/script/runsql?method=DELETE&sql=DELETE maxsession WHERE userid = 'maxadmin'
Note: I have tested this against SQL Server. Haven’t got a chance to test it against DB2 and Oracle database.
Thank for your sharing, Viet!
I have tried but it only show column name without data, could you help me?
Sounds like the query it ran doesn't return any data. You can try setting log level of the script to "INFO", run it again and see if there's error in the log file. This works with SQL Server, but the syntax might not work with Oracle or DB2. Try printing out the data in the returned resultset to see what you have in there.