Writing your First CronTask for Maximo in Java

Hi, In this turotial I will show you how to write a Cron Task for Maximo in Java and schedule it inside Maximo.

A Cron Taks is  a scheduled job which runs periodically at fixed times, dates, or intervals.

This is a very powerful feature of Maximo which can take customization to a new level. In my experience tey can be more versatile than Escalations in Maximo.

Follow the following steps to create a Cron Task

1. Write the Cron Task in Java

a. In your IDE write the following code. For the simplest of cron tasks we require to extend this SimpleCronTask class.

SimpleCronTask class implements the CronTask interface.A few notable methods of this class are below.

public void init() throws MXException 
public void start()
public void stop()
public void cronAction()

init() is called by the CronTaskManager when the class is instantiated.

start() is called only when the crontask instance is first loaded and active or when it is reloaded and active.

stop() is called when an active crontask instance is interupted by a reload request, or when the contask manager is shutting down

public void cronAction() is the “Core” method of this interface. Here you should implement your logic.

public class FirstCronTask extends SimpleCronTask {

    @Override
    public void cronAction() {
        // Your custom code here. e.g. A sample code is below.
        MXServer mxs;
        try {
            System.out.println("MyFirstCrontask: STARTING CRONTASK");
            mxs = MXServer.getMXServer();
            UserInfo ui = this.getRunasUserInfo();
            MboSetRemote Mbo = mxs.getMboSet("WORKORDER", ui);
            Mbo.setWhere("WONUM > 1");
            Mbo.reset();
            MboRemote row = null;
            int i = 0;
            if (Mbo.count() > 0) {
                while ((row = Mbo.getMbo(i)) != null) {
                    System.out.println("MyFirstCrontask: DESCRIPTION " + row.getString("DESCRIPTION"));
                    System.out.println("MyFirstCrontask: WONUM " + row.getString("WONUM"));
                    i++;
                }
            }
            //End Sample Code
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

2. Define a New Cron Task in Maximo

a. Goto System Configuration -Platform Configuration – Cron Task Setup

Untitled

b. Create a New Cron Task

Click on the new icon to create New Cron Task. Give it any name and give the path for the  classfile we wrote in step 1 for this CronTask.

CropperCapture[34]

c. Create and schedule an Instance for the crontask

CropperCapture[36]

In the screenshot above, this instance will run every 30 seconds.

3. Check if the cron Task is running fine.

Make sure Admin Mode is off. In the history tab check if it getting populated with the data.

CropperCapture[39]

or in the code we configured it print out messages which can be seen in log. Goto logs folder and check if messages are being printed there.

CropperCapture[37]

 

Thanks for reading.

 

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s