AX 2012: Customize Controller for Batch Job

The purpose of this document is to demonstrate what power we can leverage by customizing the controller for our batch job. For simplicity, we’ll explore how we can set batch dialog fields with default values by extending SysOperationServiceController class.

Prerequisites:

It is highly recommended to go through the following posts to get a better understanding of what we have done so far in the Batch Framework series.

1. Create a simple batch job.
2. Add fields to batch job dialog.
3. Add lookup to batch job dialog.

Business Requirement:

To set batch dialog fields with default values.

Project Overview:

Untitled

Development Steps:

1. Create a new class MAKSalesTableServiceController extending SysOperationServiceController base class.

class MAKSalesTableServiceController extends SysOperationServiceController
{
}

2. Override the new method and give the following definition:

public void new()
{
    super();

    this.parmClassName(classStr(MAKSalesTableService));
    this.parmMethodName(methodStr(MAKSalesTableService, processRecords));
}

3. Create a new method main and give the following definition. This is where the magic happens. The controller is used to get reference to data contract object which is then modified to initialize data members, by calling their parm methods, with default values.

static void main(Args _args)
{
    MAKSalesTableServiceController  controller;
    MAKSalesTableContract           dataContract;

    controller = new MAKSalesTableServiceController();

    // Run operation synchronously, asynchronously or in batch
    // Async execution requires service to be published
    // in the AxClient service group
    controller.parmExecutionMode(SysOperationExecutionMode::ReliableAsynchronous);

    // Get the contract from the controller and initialize it default values
    dataContract = controller.getDataContractObject();
    dataContract.parmFromDate(systemDateGet());
    dataContract.parmToDate(systemDateGet());
    dataContract.parmSalesChannel("Direct");

    // call the operation. The controller will handle execution mode
    controller.startOperation();
}

4. Modify Menu Items > Action > MAKSalesTableService to point to MAKSalesTableServiceController class just created.

Untitled

5. Compile and generate incremental CIL.
6. Click Tools > Caches > Refresh elements to refresh the AOD cache to reflect changes on the batch dialog.
7. Click Menu Items > Action > MAKSalesTableService to run the batch job.
8. You should now be getting batch dialog fields initialized with default values 🙂

Untitled

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