Movement Journal Uploading using Excel x++ in Ax 2012
static void Aks_CreateMovementJournal(Args _args)
{
Dialog dialog;
Filename filename;
DialogField dialogFilename;
//To filter the files while selecting
container conFilter = ["Microsoft Excel 97-2003 Worksheet (.xls)" ,"*.xlsx"];
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
int row=1;
ItemId itemId;
InventJournalTable journalTable;
InventJournalTableData journalTableData;
InventJournalTrans inventJournalTrans;
InventDim toInventDim,frominventDim;
TransDate transDate;
InventQtyJournal inventQtyJournal;
InventBatchId inventBatchId, toinventBatchId;
InventDimId inventDimId;
InventSiteId inventSiteId,toinventSiteId;
WMSLocationId wMSLocationId,towMSLocationId;
InventLocationId inventLocationId,toinventLocationId;
EcoResItemColorName inventcolorid;
InventSerialId inventSerialId;
real CostAmount;
real costprice;
container ledgerDimensions;
container accountCon;
int dimCount;
str 20 mainAccount;
// LedgerDimensionAccount LedgerDimensionAccount;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new dialog();
dialog.caption("select a file");
//dialogFilename = dialog.addField(typeId(FilenameOpen));
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
}
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error("File cannot be opened.");
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
do
{
row++;
transDate = cells.item(row,1).value().date();
itemId = cells.item(row,2).value().bStr();
// inventQtyJournal = cells.item(row,3).value().double();
inventSiteId= cells.item(row,3).value().bStr();
inventLocationId = cells.item(row,4).value().bStr();
inventcolorid = cells.item(row,5).value().bStr();
inventBatchId = cells.item(row,6).value().bStr();
wMSLocationId = cells.item(row,7).value().bStr();
inventSerialId = cells.item(row,8).value().bStr();
inventQtyJournal = cells.item(row,9).value().double();
costprice = cells.item(row,10).value().double();
CostAmount = cells.item(row,11).value().double();
mainAccount = cells.item(row,12).value().bStr();
Ttsbegin;
inventJournalTrans.clear();
inventJournalTrans.JournalId = 'AKS-000232';
inventJournalTrans.JournalType = InventJournalType::Movement;
inventJournalTrans.TransDate = transDate;
inventJournalTrans.ItemId = itemId;
inventJournalTrans.Qty = inventQtyJournal ;
inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId), False, False);
// Dimensions From which the transfer performs
frominventDim.InventSiteId = inventSiteId;
frominventDim.InventLocationId =inventLocationId;
frominventDim.inventBatchId = inventBatchId;
frominventDim.wMSLocationId = wMSLocationId;
frominventDim.InventColorId = inventcolorid;
frominventDim.inventSerialId =inventSerialId;
inventJournalTrans.InventDimId = InventDim::findOrCreate(frominventDim).inventDimId;
inventJournalTrans.CostPrice = costprice;
inventJournalTrans.CostAmount = CostAmount;
accountCon = ["MainAccount", mainAccount];
inventJournalTrans.LedgerDimension = AxdDimensionUtil::getLedgerAccountId(accountCon);
inventJournalTrans.insert();
ttsCommit;
// info(strfmt("%1",inventJournalTrans.ItemId));
type = cells.item(row+1, 1).value().variantType();
} while(type != COMVariantType::VT_EMPTY);
workbooks.close();
application.quit();
info("Operation/Processing Completed");
}
Thanks,
Akshay