Solution to read CSV file data to AX.
NS: you can set a delimitter to any charachter in InFielddelimitter() Method.
static void CSVtoAX(Args _args)
{
#File
CommaTextIo commaTextIo;
FileIOPermission permission;
container containFromRead;
int x;
int cols;
;
commaTextIo = new CommaTextIO('u:\\items.csv',#io_read);
commaTextIo.inFieldDelimiter(';');
containFromRead = commaTextIo.read();
While(containFromRead)
{
cols = conLen(containFromRead);
for(x=1;x<=cols;x++)
{
print conpeek(containFromRead,x);
}
containFromRead = commaTextIo.read();
}
pause;
commaTextIo = null;
}
Translate
Monday, August 1, 2011
Writing date to Txt file
Here is a solution for writing a date to Text file from Dynamics Ax.
Before running this code a physical file should be created as specified in the code('u:\\items.txt')
static void DataToTxtFile(Args _args)
{
TextIO file;
container line;
InventTable invenTable;
{
TextIO file;
container line;
InventTable invenTable;
#define.filename('u:\\items.txt')
#File
;
file = new TextIO(#filename, #io_write);#File
;
if (!file || file.status() != IO_Status::Ok)
{
throw error("File cannot be opened.");
}
file.outFieldDelimiter(';');// for semicolon seperator
while select invenTable
{
throw error("File cannot be opened.");
}
file.outFieldDelimiter(';');// for semicolon seperator
while select invenTable
{
line = [invenTable.ItemId,invenTable.ItemName,invenTable.ItemGroupId];
file.writeExp(line);
}
}
line = [invenTable.ItemId,invenTable.ItemName,invenTable.ItemGroupId];
file.writeExp(line);
}
}
Subscribe to:
Posts (Atom)