RE: Import Movement Journal through Excel with x++
Hi Ludwig Reinhard
I really really appreciate your help!
I have created a job to import the excel file and there is one little problem.
which is - When I post the excel file, it says posted and Movement journal is created but when I check the movement journal in the form, the lines are not created
Can you tell me the issue by seeing my code ?
Here it is-
static void InsertRecords(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
Name name;
FileName filename;
int row =1;
InventJournalTable journalTable;
InventJournalTrans journalTrans;
InventJournalTableData journalTableData;
InventJournalTransData journalTransData;
InventTable inventTable;
InventDim inventDim,_inventDim;
int i=1;
InventDimCombination inventDimCombination;
EcoResProductMaster ecoResProductMaster;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
InventLocation inventLocation;
ItemId itemid;
TransDate transdate;
str NewField;
Dialog dialog;
DialogField dialogField;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
dialog = new Dialog("FileOpen");
dialogfield = dialog.addField(extendedTypeStr(Filenameopen), "File Name");
dialog.run();
if (dialog.run())
{
filename = (dialogfield.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
{
//Incrementing the row line to next Row
if(i == 1)
{
journalTableData = JournalTableData::newTable(journalTable);
journalTransData = journalTableData.journalStatic().newJournalTransData(journalTrans,journalTableData);
// Init JournalTable
journalTable.clear();
journalTable.JournalId = journalTableData.nextJournalId();
journalTable.JournalType = InventJournalType::Movement;
journalTable.JournalNameId = journalTableData.journalStatic().standardJournalNameId(journalTable.JournalType);
journalTableData.initFromJournalName(journalTableData.journalStatic().findJournalName(journalTable.JournalNameId));
journalTable.insert();
journalTrans.clear();
i ;
}
try
{
row ;
journalTrans.clear();
journalTransData.initFromJournalTable();
journalTrans.TransDate = systemDateGet();//mkDate(15,11,2013);
journalTrans.ItemId = cells.item(row,2).value().bStr();
inventDim.clear();
inventDim.InventSiteId = inventLocation.InventSiteId;//
inventDim.InventLocationId = cells.item(row,4).value().bStr();//Ware House
select firstFast inventLocation where inventLocation.InventLocationId == inventDim.InventLocationId;
inventDim.wMSLocationId = cells.item(row,5).value().bStr();//A-01-00
journalTrans.Qty = Cells.item(Row,6).value().double();//.float();//.double(); //date();
journalTrans.CostPrice = decRound(cells.item(row,7).value().double(),2);
journalTrans.CostAmount = journalTrans.Qty * journalTrans.CostPrice;
// journalTrans.LedgerDimension = cells.item(row,9).value().toString();//.bStr();//double();//.bStr();
// inventDim.configId =cells.item(row,15).value().bStr();//here (EcoResConfiguration)=color
// inventDim.inventBatchId = cells.item(row,7).value().bStr();
//inventDim.inventSerialId = cells.item(row,16).value().bStr();
//inventDim.InventLocationId = cells.item(row,14).value().bStr();*/
//for offset account
// journalTrans.LedgerDimension = cells.item(row,14).value().toString();//.bStr();//double();//.bStr();
// _inventDim=inventDim::findOrCreate(inventDim);
// journalTrans.InventDimId = _inventDim.inventDimId;//"FCC-000153";
// journalTransData.insert();
_inventDim=inventDim::findOrCreate(inventDim);
journalTrans.InventDimId = _inventDim.inventDimId;//"FCC-000153";
journalTrans.insert();
// Loads the next row into the variant type and validating that its is empty or not
type = cells.item(row 1, 1).value().variantType();
row ;
}
catch
{
throw error("error");
}
}
while (type != COMVariantType::VT_EMPTY);
// quits the application
application.quit();
info(strFmt("Inventory Journal Imported :%1",journalTable.JournalId));
}