Add Lookup to Batch Job Dialog in Ax 2012
Prerequisites:
Business Requirement:
To have a lookup on the batch job dialog to filter records to be
processed based on the user selected value of sales channel field on the
dialog.
Project Overview:
We’ll be adding a new UI Builder class MAKSalesTableUIBuilder and
link it with the MAKSalesTableContract class to add lookup on
the batch dialog. It is highly recommended to read the prerequisites first
before proceeding any further to have better understanding of the topic.
Development steps:
1. Add salesChannel variable to the class declaration
of MAKSalesTableContract class to store sales channel value:
[DataContractAttribute]
class
MAKSalesTableContract
{
TransDate fromDate;
TransDate toDate;
MAKSalesChannel salesChannel;
}
2. Add parm method for sales channel variable to designate it as a data
member of the contract class:
[
DataMemberAttribute,
SysOperationLabelAttribute(literalStr("Sales channel")),
SysOperationHelpTextAttribute(literalStr("Pick sales channel")),
SysOperationDisplayOrderAttribute('3')
]
public
MAKSalesChannel parmSalesChannel(MAKSalesChannel _salesChannel = salesChannel)
{
salesChannel = _salesChannel;
return salesChannel;
}
3. Compile and generate incremental CIL.
4. Click Tools > Caches > Refresh elements to refresh the AOD cache to reflect changes on the batch dialog.
5. You should be able to see newly added Sales channel field on the batch dialog but without a lookup.
4. Click Tools > Caches > Refresh elements to refresh the AOD cache to reflect changes on the batch dialog.
5. You should be able to see newly added Sales channel field on the batch dialog but without a lookup.
6. Create a new class MAKSalesTableUIBuilder which
extends SysOperationAutomaticUIBuilder base class:
class
MAKSalesTableUIBuilder extends SysOperationAutomaticUIBuilder
{
#define.lookupAlways(2)
DialogField fromDateField;
DialogField toDateField;
DialogField salesChannelField;
}
7. Override the postBuild method of the base class to
get the references to dialog field controls after creation:
public
void postBuild()
{
super();
//Get references to dialog controls after
creation
fromDateField =
this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(MAKSalesTableContract, parmFromDate));
toDateField =
this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(MAKSalesTableContract, parmToDate));
salesChannelField =
this.bindInfo().getDialogField(
this.dataContractObject(),
methodStr(MAKSalesTableContract, parmSalesChannel));
//Change text field metadata to add lookup
salesChannelField.lookupButton(#lookupAlways);
}
8. Override the postRun method of the base class to
register the custom lookup method salesChannelFieldLookup with
the form control event lookup:
public
void postRun()
{
super();
//Register overrides for form control
events
salesChannelField.registerOverrideMethod(
methodstr(FormStringControl, lookup),
methodstr(MAKSalesTableUIBuilder,
salesChannelFieldLookup),
this);
}
9. Give the following implementation for the custom lookup method salesChannelFieldLookup:
public
void salesChannelFieldLookup(FormStringControl _control)
{
Query query;
QueryBuildDataSource qbdsMAKSalesTable;
SysTableLookup sysTableLookup;
query = new Query();
qbdsMAKSalesTable =
query.addDataSource(tableNum(MAKSalesTable));
qbdsMAKSalesTable.fields().clearFieldList();
qbdsMAKSalesTable.fields().addField(fieldNum(MAKSalesTable,
SalesChannel));
qbdsMAKSalesTable.addGroupByField(fieldNum(MAKSalesTable,
SalesChannel));
sysTableLookup =
SysTableLookup::newParameters(tableNum(MAKSalesTable), _control);
sysTableLookup.addLookupfield(fieldNum(MAKSalesTable, SalesChannel));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
10. Lastly, modify the class declaration of MAKSalesTableContract class
to link it with the MAKSalesTableUIBuilderclass we just created by
decorating it with the SysOperationContractProcessingAttribute:
[
DataContractAttribute,
SysOperationContractProcessingAttribute(classStr(MAKSalesTableUIBuilder))
]
class
MAKSalesTableContract
{
TransDate fromDate;
TransDate toDate;
MAKSalesChannel salesChannel;
}
11. Compile and generate incremental CIL.
12. Click Tools > Caches > Refresh elements to refresh the AOD cache to reflect changes on the batch dialog.
13. Click on the menu item MAKSalesTableService to run the batch job dialog.
14. You should now be getting a lookup generated for the Sales channel field on the batch dialog
12. Click Tools > Caches > Refresh elements to refresh the AOD cache to reflect changes on the batch dialog.
13. Click on the menu item MAKSalesTableService to run the batch job dialog.
14. You should now be getting a lookup generated for the Sales channel field on the batch dialog
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.
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