Calling an Autoscript from a Cron Task

The use of Autoscripts is slowly taking the place of Java Class file development for customization, but did you know that an Autoscript can also be scheduled to run based on Cron tasks?  That’s right, you can trigger an autoscript with a cron task. Here is how you can do it:

When an automation script runs as part of a cron task, the automation script does not require a launch point. You reference the com.ibm.tivoli.maximo.script.ScriptCrontask 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.

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:
  1. In the Cron Task Instances section, add a row.
  2. Specify the cron task instance name.
  3. Set the schedule for when the cron task is run.
  4. Select Run As User. The security authorizations that are granted to the specified user determines whether business logic that is related to the 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 checkbox to activate the cron task instance.
  • Save the record.

Now your script will run based on your 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.
  • You can pass in parameters to the script by using the SCRIPTARG parameter. This is a comma-delimited list of values. To access it in your script, you access a variable called ‘arg’. Here is an example: 
    if arg:
    srOwner,wfProcess = arg.split(“,”)

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