Cron tasks are jobs that run automatically on a fixed schedule within Maximo. They include important jobs such as the PM Work Order Generation Cron Task, the Inventory Replenishment Cron Task, and others.
There may be times when you come across some requirements where creating your own Cron Task provides the best solution. In previous releases of Maximo, it was required to write a custom Java class to perform the action of the Cron Task when the schedule came due. Therefore, many times we turned to Escalations to provide solutions where scheduled tasks were required.
In Maximo 7.6, you can now run an Automation Script directly from a Cron Task. This article will walk through how to configure this.
Step 1: Create a new Automation Script
Log into Maximo as an administrative user.
Navigate to the System Configuration > Platform Configuration > Automation Scripts application.
From the Select Action menu, choose the Create > Script option.
Populate the appropriate fields on your new script:
Script: CRONSCRIPT
Description: Automation Script called from a Cron Task
Script Language: python
Log Level: ERROR
Source: print ‘Automation Script called from a Cron Task’
Click the Create button to create the new script
Press the Close button on the ensuing dialog
Locate the new CRONSCRIPT script in the list, and open the script
Update the Script Source as follows, and press the Save button when finished:
#######################
# Script to generate an SR for a monthly equipment audit
#######################
from psdi.server import MXServer
# Get the variables from the cron task arguments
srDesc = 'Monthly Equipment Audit'
srOwner = 'WILSON'
if arg:
srDesc,srOwner = arg.split(',')
# Create the SR
srSet = None
try:
srSet = MXServer.getMXServer().getMboSet('SR', runAsUserInfo)
srMbo = srSet.add()
srMbo.setValue('DESCRIPTION', srDesc)
srMbo.setValue('OWNER', srOwner)
srSet.save()
finally:
if srSet:
srSet.close()
#######################
# End of Script
#######################
A few things to note with this source code:
This script will create a new Service Request and populate the Description and Owner fields
Notice that there are a few implicit variables that Maximo creates for use in the script:
arg: This is a delimited list of arguments that you wish to pass into the script. We will show below how to populate the arguments when we create our Cron Task.
runAsUserInfo: This variable gives the script access to the user profile that the cron task is running as. This will allow you to fetch Mbo Sets or perform other tasks with a set of credentials.
instanceName: While this variable is not utilized in the above script, it represents the Cron Task Instance Name that the script is being called from. This could be useful in the cases where you have multiple cron task instances and need to distinguish which one is actively running.
You can utilize the MXServer.getMXServer().getMboSet() method to fetch MBO sets of any record set that the runAsUserInfo profile has access to. Please note the strategy for closing MBO sets when you are finished with them. This alerts the JVM that the object is ready to be garbage collected. It’s important to follow this strategy, or a similar strategy, to avoid potential memory leaks with the JVM.
Now that we have a script, we can create a Cron Task to call it.
Step 2: Create a new Cron Task
Log into Maximo as an administrative user.
Navigate to the System Configuration > Platform Configuration > Cron Task Setup application.
Click the New Cron Task Definition button on the toolbar or under the Common Actions menu.
Cron Task: MYCRON (give your cron task an appropriate identifier)
Description: My Cron Task (give your cron task an appropriate description)
Class: com.ibm.tivoli.maximo.script.ScriptCrontask (this is the key to the setup, the value is case sensitive and must be exact)
Click the Save button
Click the New Row button under the Cron Task Instances table
Cron Task Instance Name: MYCRON01 (give your cron task instance an appropriate identifier)
Description: My Cron Task Instance 01 (give your cron task instance an appropriate description)
Schedule: 1M,0,0,0,1,*,*,*,*,* (this will schedule the task to run on the first of every month; use the schedule builder to select the schedule that you want your cron task to run on)
Run as User: MAXADMIN (select the user that you want the cron task to run as)
Active: Yes
Click the Save button
There should be two new parameters in the Cron Task Parameters table at the bottom of the page.
SCRIPTARG: This parameter is used to pass in variables to the script. You can separate variables by a comma or other delimiter in order to pass in more than one variable to the script.
SCRIPTNAME: This parameter tells Maximo which Automation Script to trigger when the cron task runs.
Fill out the above parameters and click the Save button. The SCRIPTNAME parameter is required, but the SCRIPTARG parameter is optional.
At this point, the Cron Task is configured and ready to go. When the cron task runs it will call the script with the arguments specified in the parameters table.
If you have any trouble, or have questions on how this works, please leave feedback in the comments below.
Alex Walter is the Chief Innovation Officer at the A3J Group, a company he formed to address the need for innovative software solutions and integrated consulting services within the EAM industry. Alex brings 17 plus years of experience in business consulting in various industries including Life Sciences, Oil and Gas, Water and Waste Management, Education, Government Facilities, among others.
Alex lives in Tampa, FL with his wife, two sons, and dogs. In his free time, he enjoys running half marathons, making space in his garage for new camping and outdoor equipment, traveling to far off places with the Walter Circus, and remaining hopeful that his NY Jets' best days are ahead of them and not behind.
3 Thoughts on “Run an Automation Script from a Cron Task in Maximo”
Question: The argument values defined at Crontask SCRIPTARG and also in the script itself. So since the argument values are defined (hardcoded) in the script, what is the value at SCRIPTARG for?
The SCRIPTARG Cron Task parameter is converted into an implicit variable in the Automation Script called arg. This variable can then be utilized in the script. For example, you might have a script that has slightly different behavior based upon which Site you’re operating on. You can use the SCRIPTARG parameter to pass in the Site ID for the current Cron Task Instance. A different instance on a different schedule might be for a different Site. Rather than having two scripts that do mostly the same thing, you can pass the Site ID into the one script. Hopefully this helps.
MxApprove End User License Agreement
If you agree to the terms of this MxApprove End User License Agreement (the “License Agreement”), click the Accept License Agreement button after reviewing the contents of this License Agreement to proceed with accessing the MxApprove (the “Application”). IF YOU DO NOT AGREE TO THE TERMS OF THE THIS LICENSE AGREEMENT, YOU WILL NOT HAVE ACCESS TO THE APPLICATION.
This is a license agreement between you, as the licensee and A3J Group LLC, a Delaware limited liability company, (“A3J”), its successors and assigns, its affiliated companies, and its authorized distributors and resellers as the licensor. This is not a contract for sale of the Application, but a license to use the Application subject to the terms and conditions of this License Agreement. Please read the terms carefully. You and A3J agree as follows:
Application.
The Application is the property of A3J. The term Application includes any related documentation, updates and permitted copies of the Application licensed to you by A3J. A3J expressly reserves all rights not expressly granted you.
Scope of License.
Upon your acceptance of the terms contained in this License Agreement, A3J grants you a nonexclusive, nontransferable, limited right to use the Application for personal or business use on the Licensed Devices, as defined below. The term "Use" means to install and access the Application in conjunction with the Application’s related and compatible software.
“Primary Device” shall mean the mobile device, tablet or other device compatible with applications owned or controlled by you, on which you download and install the Application and agree to be bound by the terms of this License Agreement and any other agreement associated with the Application. “Licensed Devices” shall mean the Primary Device and any other device that synchs or otherwise shares the same cloud or backup identification as the Primary Device.
This License Agreement does not allow you to use the Application on any device that you do not own or control. You may not distribute or make the Application available over a network where it could be used by multiple devices at the same time. You may not rent, lease, lend, sell, redistribute or sublicense the Application. You may not assign any right granted under this License Agreement without A3J’s prior written consent. You may not copy the Application. YOU AGREE THAT YOU WILL NOT MODIFY, ADAPT, TRANSLATE, ALTER NOR CREATE DERIVATIVE WORKS OF THE APPLICATION. YOU FURTHER AGREE THAT YOU WILL NOT REVERSE ENGINEER, DECOMPILE, DECRYPT, DISASSEMBLE, NOR SEEK TO DISCOVER THE SOURCE CODE OF THE APPLICATION OR ANY UPDATES ASSOCIATED THEREWITH. IF THE APPLICATION CONTAINS EMBEDDING BITS THAT LIMIT THE CAPABILITIES OF THE APPLICATION, YOU MAY NOT CHANGE OR ALTER THE EMBEDDING BITS.
Embedding of the Application is prohibited. You may NOT otherwise embed the Application. For example and without limitation: (i) You may NOT embed the Application into your hardware, software or other products, such as, application programs, electronic games, e-books, kiosks, printers, etc.; (ii) You may NOT embed the Application into your web pages; and (iii) You may NOT embed the Application into electronic commercial documents. This means that the Application may not be embedded or otherwise used in non-static files that may be accessed by computers or other devices that are NOT Licensed Devices.
A breach of these restrictions may subject you to prosecution and damages, including but not limited equitable relief in the form of an injunction.
Any updates or supplements to the Application will be governed by this License Agreement, unless a separate license agreement accompanies the update or supplement.
Intellectual Property Rights.
The Application, and any trademark, copyrights, patents, or any rights associated with the same, are the intellectual property of A3J. A3J reserves all of its rights under applicable laws. You acknowledge that the structure, organization and code of the Application are valuable trade secrets and confidential information of A3J and you shall not use this proprietary content, information or materials in any way except as expressly permitted under this License Agreement.
No Other Use.
You are granted only the rights expressly stated in this Agreement, and you may not use the Application for any other use or purpose. In addition to other prohibited uses described in this Agreement and without limitation, the following uses are specifically prohibited: (i) You may not share the Application with other individuals or business entities; (ii) You may not use the Application on more than the permitted Licensed Devices; (iii) You may not change the name of the Application; (iv) You may not translate the Application into other platforms.
Consent to Use Data.
A3J may collect and use technical data and related information, including but not limited to technical information about your device, system and application software gathered periodically to facilitate the provision of software updates, product support and other services related to the Application. A3J may use this information, provided this use does not personally identify you, to modify or further develop the Application and/or provide additional technologies to you.
Termination.
The license rights granted under this License Agreement are effective until terminated by you or A3J. Your rights under this License Agreement will terminate automatically without notice from A3J if you fail to comply with any of the term(s) of this License Agreement. Upon termination of the license, you shall cease all use of the Application, and destroy all copies, if any, full or partial, of the Application.
No Warranty.
YOU EXPRESSLY ACKNOWLEDGE AND AGREE THAT USE OF THE LICENSED APPLICATION IS AT YOUR SOLE RISK. TO THE EXTENT PERMITTED BY LAW, THE APPLICATION IS PROVIDED “AS-IS” AND “AS AVAILABLE,” WITH ALL FAULTS AND WITHOUT WARRANTY OF ANY KIND. A3J DOES NOT AND CANNOT WARRANT THE PERFORMANCE OR RESULTS YOU MAY OBTAIN BY USING THE APPLICATION. A3J MAKES NO WARRANTIES, CONDITIONS, REPRESENTATIONS OR TERMS, EXPRESS OR IMPLIED, WHETHER BY STATUTE, COMMON LAW, CUSTOM, USAGE OR OTHERWISE AS TO OTHER MATTERS, INCLUDING WITHOUT LIMITATION, NON INFRINGEMENT OF THIRD PARTY RIGHTS, TITLE, INTEGRATION, SATISFACTORY QUALITY, MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. FURTHER, A3J MAKES NO WARRANTIES AGAINST INTERFERENCE WITH YOUR ENJOYMENT OF THE APPLICATION OR THAT THE APPLICATION WILL MEET YOUR REQUIREMENTS, THAT THE OPERATION AND USE OF THE APPLICATION WILL BE UNINTERRUPTED OR ERROR-FREE OR THAT DEFECTS IN THE APPLICATION WILL BE CORRECTED. IN THE EVENT THE APPLICATION PROVES DEFECTIVE, YOU ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED WARRANTIES OR LIMITATIONS PLACED ON STATUTORY RIGHTS, SO THE ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
Damage Limitations.
TO THE EXTENT NOT PROHIBITED BY LAW, IN NO EVENT SHALL A3J BE LIABLE FOR PERSONAL INJURY, OR ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES WHATSOEVER, INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, LOSS OF DATA, BUSINESS INTERRUPTION OR ANY OTHER COMMERCIAL DAMAGES OR LOSSES, ARISING OUT OF OR RELATED TO YOUR USE OR INABILITY TO USE THE APPLICATION, HOWEVER CAUSED, REGARDLESS OF THE THEORY OF LIABILITY (CONTRACT, TORT OR OTHERWISE) AND EVEN IF A3J HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. In no event shall A3J’s cumulative liability for any loss or damage to you (other than as may be required by applicable law in cases involving personal injury) exceed the amount of fifty dollars (US$50.00). The foregoing limitations will apply even if the above-stated remedy fails of its essential purpose.
No Export or Re-Export.
You may not use or otherwise export or “re-export” the Application. Specifically, and without limitation, you may not export or re-export the Application into (a) U.S. embargoed countries or (b) to anyone on the U.S. Treasury Department’s list of Specially Designated Nationals or the U.S. Department of Commerce Denied Person’s List or Entity List. By downloading and installing the Application and agreeing to the terms of this License Agreement you represent and warrant that you are not located in such a country or a person or entity on any such list. You further warrant and represent that you will not use the Application for any purpose prohibited by the laws of the United States.
Governing Law.
This Agreement is governed by the laws of the State of Florida, United States of America, excluding conflict of laws provisions and excluding the United Nations Convention on Contracts for the International Sale of Goods. You expressly agree that any disputes related to this Agreement will be resolved in the Circuit Court of Hillsborough County, Florida, U.S.A., or the United States District Court for the Middle District of Florida, U.S.A. Both you and A3J consent to the personal jurisdiction and venue of those courts. If any part of this Agreement is found void and unenforceable the balance of the Agreement will remain valid and enforceable according to its terms.
This License Agreement represents the entire agreement between you and A3J in connection with its subject matter. This License Agreement may only be modified by A3J in a writing that expressly states that the writing is intended to modify this License Agreement.
Contacting A3J.
A3J has a mailing address of 3225 S. MacDill Avenue, Tampa, Florida 33629, U.S.A. All support requests, completed registrations and other inquiries should be sent via e-mail to info@a3jgroup.com.
Question: The argument values defined at Crontask SCRIPTARG and also in the script itself. So since the argument values are defined (hardcoded) in the script, what is the value at SCRIPTARG for?
The SCRIPTARG Cron Task parameter is converted into an implicit variable in the Automation Script called arg. This variable can then be utilized in the script. For example, you might have a script that has slightly different behavior based upon which Site you’re operating on. You can use the SCRIPTARG parameter to pass in the Site ID for the current Cron Task Instance. A different instance on a different schedule might be for a different Site. Rather than having two scripts that do mostly the same thing, you can pass the Site ID into the one script. Hopefully this helps.
Very good script and feature, thanks a lot