Hi Everyone,
Here I posted the X++ code for Inserting Text File values into Invent Table.
Inserting Values to Invent Table from Text File
FilenameOpen filename;dialogField dialogFilename;Dialog dialog;TextIO file;container con;InventTable inventTable1,inventTable2;InventTableModule inventTableModule;InventItemGroup inventItemGroup,inventItemGroup1;ItemGroupId itemGroupId,itemGroupId1;ItemId itemId;str conItem,conItemGroup;#File;dialog = new Dialog("ISIS Bulk Upoad");dialogFilename = dialog.addField(typeId(FilenameOpen));dialog.filenameLookupFilter(["@SYS15896",#Mactxt]); //Create a macro in #File to open all text files(*.txt)dialog.filenameLookupTitle("Upload from Text File");dialog.caption("Upload from text file");dialogFilename.value(filename);if(!dialog.run())return;filename = dialogFilename.value();try{file = new TextIO(filename, #IO_READ);if (!file)throw Exception::Error;file.inRecordDelimiter(‘\n’); //For Next Recordfile.inFieldDelimiter(‘\t’); //For Next Column valuettsbegin;while(file.status() == IO_STATUS::OK){con = file.read();conItem = conpeek(con,1);conItemGroup = conpeek(con,3);if(conItem!="0"){itemId = substr(conItem,1,8);ItemGroupId = substr(conItemGroup,2,13);//Item Group Table InsertinventItemGroup1 = inventItemGroup::find(ItemGroupId);if(inventItemGroup1){info(strfmt("ItemGroup (%1) already exist",ItemGroupId));}else{inventItemGroup.ItemGroupId = ItemGroupId;inventItemGroup.insert();info(strfmt("ItemGroup (%1) Inserted Successfully",ItemGroupId));}//Item Group Table Insert End//Invent Table InsertinventTable1 = inventTable::find(ItemId);itemGroupId1 = inventTable::find(ItemId).ItemGroupId;if(inventTable1){if(itemGroupId1 != ItemGroupId){inventTable2.ItemGroupId = ItemGroupId;inventTable2.update();info(strfmt("ItemGroup for Item (%1) Updated successfully",itemId));}else{info(strfmt("Item (%1) and ItemGroup (%2) already exist",itemId,itemGroupId));}}else{//Invent Table InsertinventTable2.initValue();inventTable2.ItemId = itemId;inventTable2.ItemGroupId = ItemGroupId;inventTable2.DimGroupId = "N – W";inventTable2.ModelGroupId = Enum2str(InventModel::FIFO);inventTable2.insert();select forupdate inventTableModule;// CostinventTableModule.initValue();inventTableModule.ItemId = ItemId;inventTableModule.ModuleType = ModuleInventPurchSales::Invent;inventTableModule.insert();// Purchase orderinventTableModule.initValue();inventTableModule.ItemId = ItemId;inventTableModule.ModuleType = ModuleInventPurchSales::Purch;inventTableModule.insert();// Sales orderinventTableModule.initValue();inventTableModule.ItemId = ItemId;inventTableModule.ModuleType = ModuleInventPurchSales::Sales;inventTableModule.insert();//Invent Item Location InsertinventItemLocation.ItemId = ItemId;inventItemLocation.inventDimId = InventDim::inventDimIdBlank();inventItemLocation.insert();info(strfmt("Item and ItemGroup for Item (%1) Inserted successfully",itemId));}}//Null check}//Whilettscommit;}catch(Exception::Error){Error("Upload Failed");}
Text File Format that I used for Upload :
Leave a comment