Skip to main content

Calling External Python File/Libraries with "mxe.pylib.path" in IBM Maximo

Greetings,

Automation Scripting is a powerful tool in Maximo that can be used to customize the Out Of Box (OOB) behavior of Maximo without the need to deploy any class file which requires downtime of the system. While automation script provides the ability to write code into multiple different languages and their versions like Python, Jython, JavaScript, and Nashhorn, etc. Python/Jython remains the most popular language they use.

One of the most powerful features of Python is the availability of reusable libraries available to achieve many tasks. Many times a requirement need an external library to be called Automation Scripting which can be done much more easily with Maximo 7.6.1.2 onwards.

In this use case, we have written an action script that will be called when the user presses the Test button on the Work Order application.

This automation script contains the logic to call another external file with the name externalPy.py. We create a folder in the application server and place this file into the folder.  

The code in externalPy looks like-

def callExtrnalPy():
return "Hello from External Py"

Maximo 7.6.1.2 onwards there is a system property "mxe.pylib.path" has been added. The value of this property can be set to the path of this folder. 

Below is the code which we use on the action script which will be called when Test button will be clicked on Work Order Tracking application-

from psdi.server import MXServer
import sys

mxServer = MXServer.getMXServer()
userInfo = mxServer.getUserInfo("MAXADMIN")

PropSet = MXServer.getMXServer().getMboSet("maxpropvalue", userInfo)
PropSet.setWhere("PROPNAME = 'mxe.pylib.path'")
PropSet.reset()
if PropSet.isEmpty() == False:
propMbo = PropSet.getMbo(0)
libpath = str(propMbo.getString("PROPVALUE"))

sys.path.append(libpath)
import externalPy
desc = " Calling...." + externalPy.callExtrnalPy()

raise TypeError(desc)
PropSet.close()

In case you have multiple such scripts where you are calling external libraries and if you have to change the path due to some reason, the use of this system property helps to ensure that the new folder path gets updated in one place rather than changing the path into each automation script.


Important to note that the libraries which you are planning to place in this external folder must be compatible with the Python Libraries version available with Maximo.

Hope this post has helped you to get a better understanding of how to call the external libraries or code files using Automation Script and manage them effectively. If yes, then like this blog post and video.


Comments

  1. Thanks for the tip. I think u will be able to get the property from ur mxServer.getProperty() method directly

    ReplyDelete
  2. Hi! i'veconfigured everything as described and i can't execute the external code, could you please help me?

    ReplyDelete

Post a Comment

Popular posts from this blog

Maximo OSLC Integration with External System- Get data in JSON format

Greetings! If you have noticed recent version of Maximo, couple new application in Integration module has been added which are OSLC Resources and OSLC Provider.These modules gives us ability to integrate with external system in JSON. OSLC is an open community that creates specifications for the integration of products and/or tools.  IBM is a leading contributor to this community and many software products within the IBM Software Group are implementing OSLC in order to enable cross-product integrations. An OSLC integration requires 2 players-  1. OSLC Consumer application 2. OSLC Provider application.   An OSLC provider application makes containers of associated resources(data) available for integration through service providers. Consumer applications then use these service providers to query resources and to create, update, and delete resource data.  The consumer application sends a query to the service provider for resource data. The service p...

Power of Maximo Formulas - Build logic w/o Custom Java code or Automation Script

Greetings! Maximo 7.6 has lot of additional capabilities added in Tivoli Automation Engine as compared to older versions of Maximo which aim to allow users to make change in applications for small requirements without actually going to customization route. Automation scripts is one of such tool given for users and technical developers to change the behavior of Maximo in case where functionalities can't be changed only via use of configuration. If we have a requirement to populate some field on basis of other fields , we can easily do that with automation script but in order to do that you still need to have knowledge of Jython or Javascript to write the logic. Maximo formula is one the tool given by IBM which can be used for such business requirements and user can make changes to Maximo logic via configuration without getting into difficulties of coding. Formulas are available from Maximo version 7603. With release of Maximo version 7606, there has been addition of new capabil...

Call publish channel w/o enabling Event Listener in Maximo

Greetings! Generally if we have to send data to external system via MIF, we create Publish Channel and enable Event Listener on publish channel. Once event listener is enabled, Maximo listens for event and send data to end point via publish channel for each Save of related MBO . But t here are many scenarios where we need to send data to external system using publish channel on specific event and not for every save. In order  to send to external system on specific event, for example - sent data to Ariba when PO status in Maximo is changed to APPR, we can use automation script or java code to call publish channel on the go. Below code can be used in automation script - server = MXServer.getMXServer() userInfo = mbo.getUserInfo() whereClause = <CONDITION> server.lookup("MIC").exportData("<Publish Channel Name>", "<External System Name>", whereClause, userInfo, 1000) Via Java class - MXServer server = MXServer.getMXServer(); ...