Sunday 4 September 2016

Use batch processing in AX 2012 using sysframework

1. Create a service operation class ABHISalesTableService having the following class declaration:

class ABHISalesTableService 
{
}

2. Create a new method in the class giving a suitable name like processRecords having the following definition:

[SysEntryPointAttribute(false)]
public void processRecords()
{
    ABHISalesTable   abhiSalesTable;
    int             counter = 0;

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

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

    //Actual operation performed
    while select forUpdate abhiSalesTable
    {
        ttsBegin;
        abhiSalesTable.Processed = NoYes::Yes;
        abhiSalesTable.update();
        ttsCommit;

        counter++;
    }

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

3. Create an action menu item ABHISalesTableService pointing to SysOperationServiceController.

4. Set the parameters of the action menu item to the service operation just created, ABHISalesTableService .processRecords.

5. Compile the service operation class and generate incremental IL.
6. Click on the action menu item to run the batch job. Check the Batch processing checkbox to run the job in CLR runtime which is the batch server execution environment.
7. Click System administration > Inquiries > Batch jobs to view the status of the job. You may also click on the Log button to view the messages written to infolog during the job execution.