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,
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,
Hi,
ReplyDeleteAm 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)