Friday, July 31, 2009

Dynamics Ax write data to file

void clicked()
{
DataArea dataArea;
Table1 tab1;
System.IO.StreamWriter file;
;
while select dataArea where dataArea.isVirtual == false
{
changeCompany(dataArea.Id)
{
tab1 = null;
file = new System.IO.StreamWriter("c:\\temp\\1\\" + dataArea.Id + ".txt");
while select tab1
{
file.WriteLine(tab1.Code + ";" + tab1.Name);
}
file.Close();
file.Dispose();
}
}
super();
}

Dynamics Ax read data from file

void clicked()
{
DataArea dataArea;
Table1 tab1;
Table2 tab2;
System.IO.StreamReader file;
System.String lineS;
str line;
str code, description;
int pos;
str path;
;
while select dataArea where dataArea.isVirtual == false
{
changeCompany(dataArea.Id)
{
tab1 = null;
tab2 = null;
select firstonly tab1;
select firstonly tab2;
path = "c:\\temp\\1\\" + dataArea.Id + ".txt";
Info::messageWinAddLine(dataArea.Id + path);
if(System.IO.File::Exists(path))
{
file = new System.IO.StreamReader(path);
lineS = file.ReadLine();
while(lineS)
{
line = lineS;
pos = strfind(line,";",strlen(line),-strlen(line));
code = substr(line,1,pos-1);
description = substr(line,pos+1,strlen(line));
tab1.Code = code;
tab1.Description = description;
tab2.Code = code;
tab2.Text = description;
Info::messageWinAddLine(code + description);
tab1.insert();
tab2.insert();
lineS = file.ReadLine();
}
file.Close();
file.Dispose();
}
}
}
super();
}