AX 2012: Add Fields to Batch Job Dialog

Posted on Updated on


1. Create a simple batch job.


To add custom fields to batch job dialog to choose a date range to process only those records falling in that date range.

Project overview:


As you can see in the picture, a data contract class MAKSalesTableContract has been added to the project to achieve the goal. We’ll be adding from date and to date fields on the batch dialog to capture the date range.

Development steps:

1. Create a new data contract class MAKSalesTableContract with the following class declaration:

class MAKSalesTableContract
    TransDate   fromDate;
    TransDate   toDate;

2. Create a new method parmFromDate with the following definition:

    SysOperationLabelAttribute(literalStr("From Date")),
    SysOperationHelpTextAttribute(literalStr("Pick a valid begin date")),
public TransDate parmFromDate(TransDate _fromDate = fromDate)
    fromDate = _fromDate;

    return fromDate;

3. Create a new method parmToDate with the following definition:

    SysOperationLabelAttribute(literalStr("To Date")),
    SysOperationHelpTextAttribute(literalStr("Pick a valid end date")),
public TransDate parmToDate(TransDate _toDate = toDate)
    toDate = _toDate;

    return toDate;

4. Update the MAKSalesTableService.processRecords method to the following definition:

public void processRecords(MAKSalesTableContract _contract)
    MAKSalesTable   makSalesTable;
    int             counter = 0;

    //Determines the runtime
    if (xSession::isCLRSession())
        info('Running in a CLR session.');
        info('Running in an interpreter session.');

        //Determines the tier
        if (isRunningOnServer())
            info('Running on the AOS.');
            info('Running on the Client.');

    //Actual operation performed
    while select forUpdate makSalesTable
        where makSalesTable.TransDate >= _contract.parmFromDate()
            && makSalesTable.TransDate <= _contract.parmToDate()
        makSalesTable.Processed = NoYes::Yes;


    info(strFmt("Successfully processed %1 records.", counter));

This is where the magic happens. Note that method now takes an input parameter of type MAKSalesTableContract class. Then it filters the records to be processed in the while loop by adding ranges to the MAKSalesTable.TransDate field, using the values given by user on the batch dialog for From Date and To Date.

5. Compile and generate incremental IL.
6. Click on Menu Items > Action > MAKSalesTableService to run the batch job.
7. You should now be having 2 fields added to the batch dialog:



Next in the series: Add lookup to batch job dialog.


Leave a Reply

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

You are commenting using your 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