Search This Blog

Friday, January 31, 2020

MAXIMO: Custom Cron Task using Automation Script

****Maximo custom CronTask using Automation Script ****



The use of Automation scripts is slowly taking the place of MBO java class file-based customization. It turns out this is also true when we will need to create custom CronTasks.

Today I am going to explain how we can create custom CronTask using Automation script.



When an automation script runs as part of a CronTask, the automation script does not require a launch point. You reference the com.ibm.tivoli.maximo.script.ScriptContask Java™ class in your cron task definition, and then you can attach an automation script to the cron task.

Step 1: create the Autoscript:

  • In the Automation Scripts application, on the List tab, select the “Create > Script” action.
  •  Specify a name, description, and log level for the script.
  •  If the script requires variables, in the Variables section, add new rows to declare the variable and bindings. You cannot specify bindings to a Maximo® business object. You can specify only LITERAL, SYSPROP, and MAXVAR bindings.
  •  Enter the source code of the automation script and click Create to save the automation script in the database.








#########################################################################################################################################################################

#

# Version       Date         Author                 Request #            Remarks

#   1.0       01/31/2020   Prashant Bavane    Test Custom CronTask   Test Custom CronTask
#

#########################################################################################################################################################################

from psdi.server import MXServer
from psdi.mbo import *

if arg:
 var1,var2=arg.split(",")

mxServer = MXServer.getMXServer()
userInfo = mxServer.getUserInfo("maxadmin")
assetMboSet = mxServergetMboSet("ASSET",userInfo)
assetMboSet.setWhere("assetnum='' and siteid='BEDFORD'")
assetMboSet.reset()
assetMbo = assetMboSet.getMbo(0)
assetMbo.setValue("DESCRIPTION",var1+"-"+var2)
assetMboSet.save()


Step 2: Creating the Cron task:

  •  In the Cron Task Setup application, create a new cron task definition.
  •  In the Class field, enter com.ibm.tivoli.maximo.script.ScriptCrontask.
  •  Create the cron task instance that runs the automation script.
  • In the Cron Task Instances section, add a row.
  • Specify the cron task instance name.
  • Set the schedule for when the cron task is run.
  • Select Run As User. The security authorizations that are granted to the specified user determines whether business logic that is related to Maximo business object can run in the script code. For example, a value cannot be set in a record unless the specified user has the security authorization to write values into that record.
  • In the Parameters tab, in the SCRIPTARG row, specify a value(s) that represents an argument for the cron task. To specify more than one value, separate them by commas.
  • In the SCRIPTNAME row, specify the name of the script that you created to run as part of the cron task. SCRIPTNAME is a mandatory parameter that must be populated. The script name that you specify is passed to the automation script in the form of the scriptName implicit variable.
  • In the Details section, select the Active check box to activate the cron task instance.
  • Save the record.


Now our script will run based on our defined cron task schedule.

Notes on the script:

  • Since this is being called from a cron task and not a screen, the ‘mbo’ object will be undefined.
  • We can pass in parameters to the script by using the SCRIPTARG parameter. This is a comma delimited list of values. To access it in our script, we access a variable called ‘arg’. Here is a example:
  if arg:
      srOwner,wfProcess = arg.split(",")

Since we can import the Java Class library, there isn’t much we can’t do with an autoscript that we can do in a cron task class file.

Cheers!!!!!!!!!!!!!!