I want to share code to import text file data to Table in axapta. Here is sample of one field taken in text file.
#define.ioRead("r")
Dialog dialog = new Dialog('File Upload');
Dialogfield dialogfield;
DialogField dialogFileName;
InventTable inventTable;
ItemID itemID;
FileIOPermission fileIOPermission;
CommaTextIo io;
container inLine;
int lineNum;
int i;
;
dialogFileName = dialog.addField(typeid(FilenameSave));
dialog.run();
if(dialog.closedOk())
{
fileIOPermission = new FileIOPermission(dialogFileName.value(), #ioRead);
fileIOPermission.assert();
io = new CommaTextIo(dialogFileName.value(), #ioRead);
if (io)
{
ttsbegin;
while (io.status() == IO_Status::Ok)
{
inLine = io.read();
if (io.status() != IO_Status::Ok)
{
break;
}
itemID = conpeek(inLine,1);
if(itemID)
{
inventTable = inventTable::find(itemID,true);
if(inventTable)
{
inventTable.ItemGroupId = conpeek(InLine,2);
inventTable.doUpdate();
i++;
}
else
{
info(strfmt('Cant find Item %1',itemID));
}
}
}
ttscommit;
}
}