Customize Controller for Batch Job in Ax 2012
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.
Business Requirement:
To set batch dialog fields with default values.
Project Overview:
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.
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
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
Comments
Post a Comment