<div style="display:inline;"> <img height="1" width="1" style="border-style:none;" alt="" src="//googleads.g.doubleclick.net/pagead/viewthroughconversion/1066880148/?value=0&amp;label=4oTQCMyJzwQQlJnd_AM&amp;guid=ON&amp;script=0">

By: Vijet Shanbhag on July 11th, 2024

Print/Save as PDF

Calling Methods from another Automation Script in Maximo

Introduction 

Maximo provides a very robust scripting environment to configure the system as per user requirements. Leveraging automation scripts is becoming a best practice over customizing java classes for several reasons with some key benefits of more efficient build, deployment and test cycles as well as maintainability during upgrades by keeping enhancements at Maximo configuration tools to future-proof upgrades for automatic upgrade capability vs manual upgrade activities involved with migrating java code customizations.  

Java still has a lot of advantages over scripting when it comes to Maximo as some UI components are not all accessible to scripting and the object-oriented feature like calling the methods is not fully implemented yet with python scripting in Maximo.  Each version release extends more hooks to leverage automation scripts so before committing to any java customizations, it is wise to first evaluate if your customization can be achieved by the existing launch points of automation scripts. 

Maximo 7.6 changed introduced of a way to define the methods in a common script file and call them from other scripts whenever necessary. This solves a key problem of having to write the same code multiple times for different scripts. This allows to leverage best practices with traditional coding into Maximo automation scripts.

Below we will create a sample script which will have 2 methods that can be called by other automation scripts.

Standalone script to define the methods.

To start with the creation of the standalone script (to define the methods), navigate to the following application and select action menus.

Check the “Allow Invoking Script Functions” check box. This allows Maximo to decide if methods from the script can be invoked from other scripts.

Graphical user interface, application
Description automatically generated

We will provide an example that you can use to demonstrate this functionality.  Copy the sample script methods below.  Both the methods will set the description on Work order and Asset when called from the calling scripts.

# Set Description for the Asset Mbo
def setDescriptionforAst(curMbo):
   
itemDesc = curMbo.getString("ITEM.DESCRIPTION");
   
desc = None;
   
loc =  curMbo.getString("LOCATION");
   
if (loc is not None):
     
desc = itemDesc + " on " + loc;
   
else:
     
desc = itemDesc;
   
curMbo.setValue("DESCRIPTION",desc);

# Set Description for the Workorder Mbo
def setDescriptionforWo(curMbo,StrVal1):
   
assetDesc = curMbo.getString("ASSET.DESCRIPTION");
   
desc = "Workorder for Asset " + StrVal1 + " : " + assetDesc;
   
curMbo.setValue("DESCRIPTION",desc);

Create Object Script on Workorder Object

To create the object script on the Workorder object, set the following settings from the object launch point dialog.

Graphical user interface, text, application
Description automatically generated

Copy the below sample code on the object script.

# Fetch Asset Number
assetNum = mbo.getString("ASSETNUM"); 

# Check asset number not null
if assetNum is not None:
   
# Pass Arguments to the called method
   
args = [mbo,assetNum];
   
# Call the method
   
service.invokeScript("COMMONSCRIPT","setDescriptionforWo",args);

Create Object Script on Asset Object

To create the object script on the Asset object, set the following settings from the object launch point dialog.

Graphical user interface, text, application, email
Description automatically generated

Copy the below sample code on the object script.

# Fetch Location
locNum = mbo.getString("LOCATION");
if locNum is not None:
   
# Set the arguments
   
args = [mbo];
   # Call the method from another script
   
service.invokeScript("COMMONSCRIPT","setDescriptionforAst",args);

 

Testing the Implementation

Workorders:
Open as existing workorder and perform an update operation. Add an Asset if not already added or update any other field and save the workorder.  The description will be updated.  

Asset: 
Open as existing asset and perform an update operation.  Add a location if not already added or update any field to perform the update operation and save.  The description on the Asset will be updated.

 

Maximo Implementation of invokeScript 

The invokeScript method is within the service object which takes script name, method name and arguments for the method as the 3 arguments.

# Call the method from another script
service.invokeScript("COMMONSCRIPT","setDescriptionforAst",args);

Methods can be invoked from all the launch points that have the service object accessible. So, this makes it easy to call the methods from Object, attribute, action, and some integration launch points without re-writing the code.

 

Advantages 

The implementation of invoking the methods saves a lot of time for code re-write and most importantly makes the maintenance of the code very easy. If future updates are required for the method, the update will need to be made at the one method. 

Since Maximo supports multiple scripting options, methods written in a jython script can be called by scripts that are written in other languages like JavaScript and vice versa.

 

Dis-advantages. 

The implementation is not robust. It is still not possible to perform all the object-oriented techniques.  Scripts cannot replace the bean class functionalities completely. Service methods are not available from many integration scripts implicitly.

 

Conclusion 

With automation scripts continuously evolving and scripting taking the center stage for Maximo customizations we can expect more stronger object-oriented concepts getting implemented with the automation scrips.  Additional features and improvements become available with each release of Maximo, so keep an eye on future releases to learn on better you can leverage automation scripts.