Skip to main content

export excel file through batch job in ax 2012

Friends,
                     Microsoft Dynamics AX 2012 have a strong batch job functionality that run on periodic time as per user requirement. I have created one batch job that will export invent table data from AX 2012 to excel file. Go through given steps and get this functionality.

Step 1 : Create Contract Class AkkInventTableDataContractBatch

[DataContractAttribute]
class AkkInventTableDataContractBatch
{
    ItemType          itemType;
}

Step 2 : Add parmItemType() method to AkkInventTableDataContractBatch class and write this
              logic,
[DataMemberAttribute]
public ItemType parmItemType(ItemType  _itemType = itemType)
{
    itemType  = _itemType;
    return itemType;
}

Step 3 : Create ServiceClass AkkInventTableBatchService

class AkkInventTableBatchService extends SysOperationServiceBase
{

}

Step 4 : Add exportExcel() method to AkkInventTableBatchService class and write this      
              logic,

[SysEntryPointAttribute(true)]
public str exportExcel(AkkInventTableDataContractBatch _dataContract)
{
    SysExcelApplication     application;
    SysExcelCells           cells;
    SysExcelCell            cell;
    SysExcelWorkbooks       workBooks;
    SysExcelWorkbook        workBook;
    SysExcelWorksheets      workSheets;
    SysExcelWorksheet       workSheet;
    InventTable             inventTable;
    int                     row;
    str                     fileName    = "C:\\Users\\Administrator\\Desktop\\InventTable.xls";

    application = SysExcelApplication::construct();
    workBooks   = application.workbooks();
    workBook    = workBooks.add();

    workSheets  = workBook.worksheets();
    workSheet   = workSheets.itemFromNum(1);

    cells       = workSheet.cells();
    cells.range('A:A').numberFormat('@');
    cell        = cells.item(1, 1);
    cell.value("Item");
    cell        = cells.item(1,2);
    cell.value("Name");
    row = 1;

    while select inventTable
            where inventTable.ItemType    == _dataContract.parmItemType()
    {
        row++;
        cell    = cells.item(row, 1);
        cell.value(inventTable.ItemId);
        cell    = cells.item(row, 2);
        cell.value(inventTable.itemName());
    }
    workBook.saveAs(fileName);
    application.visible(true);

    return "Completed";
}
Step 5 : create AkkInventTableBatchController and write this      
              logic,
class AkkInventTableBatchController extends SysOperationServiceController
{
}
Step 6 : Add defaultCaption() method to AkkInventTableBatchController class and write this      
              logic,
protected ClassDescription defaultCaption()
{
    return "Invent Table Export Data Test";
}

Step 7 : Add new() method to AkkInventTableBatchController class and write this      
              logic,

public void new()
{
    super(classStr(AkkInventTableBatchService), methodStr(AkkInventTableBatchService, exportExcel), SysOperationExecutionMode::Synchronous);
}

Step 8 : Add AkkInventTableBatchController () construct to
              AkkInventTableBatchController class and write this logic,

public static AkkInventTableBatchController construct()
{
    AkkInventTableBatchController   controller;

    controller  = new AkkInventTableBatchController();
    controller.parmShowDialog(true);
    controller.parmShowProgressForm(false);

    return controller;

}

Step 9 : Add main() method to  AkkInventTableBatchController class and write this logic,
public static void main(Args _args)
{
    AkkInventTableBatchController       controller;

    controller  = AkkInventTableBatchController::construct();
    controller.startOperation();
}

Class Looks like,


Open AkkInventTableBatchController  class and export data as per item type. like below,




Comments

  1. Hi,

    Am getting error while running in batch.


    Microsoft.Dynamics.Ax.Xpp.InvalidRemoteCallException: Exception of type 'Microsoft.Dynamics.Ax.Xpp.InvalidRemoteCallException' was thrown.

    at Dynamics.Ax.Application.SysExcelApplication.construct()

    at Dynamics.Ax.Application.AkkInventTableBatchService.Exportexcel(AkkInventTableDataContractBatch _dataContract) in AkkInventTableBatchService.exportExcel.xpp:line 15

    at AkkInventTableBatchService::exportExcel(Object , Object[] )

    at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeInstanceCall(Object instance, String MethodName, Object[] parameters)

    at Dynamics.Ax.Application.SysOperationServiceController.Runoperation(Boolean _async) in SysOperationServiceController.runOperation.xpp:line 93

    at Dynamics.Ax.Application.SysOperationServiceController.Run() in SysOperationServiceController.run.xpp:line 27

    at Dynamics.Ax.Application.BatchRun.runJobStaticCode(Int64 batchId) in BatchRun.runJobStaticCode.xpp:line 54

    at Dynamics.Ax.Application.BatchRun.runJobStatic(Int64 batchId) in BatchRun.runJobStatic.xpp:line 13

    at BatchRun::runJobStatic(Object[] )

    at Microsoft.Dynamics.Ax.Xpp.ReflectionCallHelper.MakeStaticCall(Type type, String MethodName, Object[] parameters)

    at BatchIL.taskThreadEntry(Object threadArg)



    ReplyDelete

Post a Comment

Popular posts from this blog

Drag and drop functionality in AX 2012

Friends,            Now a day every person wants drag-drop functionality i.e., No more steps, easy and fast. Yes, I have tried this functionality on ListView Control . Try this steps Step: 1          Create one form and add two new List view control in Design named ListView, ListView1. Step: 2           Open ListView Property change,                      SingleSelection : No                       ViewType : Report                       DragDrop : Manual                  NOTE : Change property in two ListView control. Step: 3            Override method init() method in form and write this code,             public void init()        {                 FormListControl listControl;                 FormListColumn  column;                 CustTable       custTable;                              super();                ListView.addColumn(1, new FormListColumn("Customer Account"));                ListView1.addColumn(1, new FormListColumn("Custom

Working with Graph in AX12012

Hi friends,               Generally graph acts as easy to understand like a diagram and 3D design also to displays information basis on the variants. Microsoft AX also supports this functionality. For that we have to follow below process. Create table and add fields as below,                   Table name : AkkMatchScore                   Fields          :                                           Name                           Type                                       OverRuns                    String15                                       Overs                           String15                                       RunsQty                      RealBase Create Form and add new control ManagedHost in design  one dialog will open , you have select Client control for chart tool box. See below image for more.                                                NOTE : Change ManagedHost control property                                       Name              :