Export data from Ax to txt file


Below is the sample code to upload the data from Ax to txt file.

static void csvtextfile(Args _args)
TextIO file;
container line,header,bottom;
HcmWorker worker;
MZK_PayrollProcessed processed,processedCount,processedNet;
HcmEmploymentEmployee payrollcurreny;
HcmWorkerBankAccount bank;
CompanyInfo company;
BankGroup BankGroup;
str IBANACC, id, EmployeeID, PayrollDate, bankCode, currencyfrom, CurrencyTo, masterCurrency;
date Pdate,sdate;
int64 counttoatl;
real net;
str name;
Mzk_PayrollTxt netSalary;
DialogField dfield;
Dialog dilaog;
#define.filename(“C:\\Users\\46509008\\Documents\\Export To Csv\\POINV_SEP12_HDR.txt”)
FileIOPermission FileIOPermission;
Filename path, name1, extention, str_filename, date1, date2;
[path, name1, extention] = fileNameSplit(#fileName);
date1 = date2str(today(), 213, DateDay::Digits2,
str_filename = curext()+date1 + extention;
file = new TextIO(strFmt(“%1\\%2”, WinAPI::getFolderPath(#CSIDL_DESKTOPDIRECTORY), str_filename), “W”);
file.outFieldDelimiter(‘,’);// for semicolon seperator

if (!file || file.status() != IO_Status::Ok)
throw error(“File cannot be opened.”);

company = CompanyInfo::findDataArea(curext());
while select count(RecId) from processedCount
where processedCount.MZK_MonthYear == MZK_MonthYear::MAR2013
&& processedCount.dataAreaId == curext()
counttoatl = processedCount.RecId;
while select sum(NetSalary) from processedNet
where processedNet.MZK_MonthYear == MZK_MonthYear::MAR2013
&& processedNet.dataAreaId == curext()
net = processedNet.NetSalary;

//file upload start
header = [‘H,P’];
while select processed //My main table of Payroll
where processed.MZK_MonthYear == MZK_MonthYear::MAY2013
&& processed.dataAreaId == curext()
&& processed.Mzk_PaymentMethod == Mzk_PaymentMethod::Bank
worker= HcmWorker::find(processed.Worker);
bank = HcmWorkerBankAccount::findByWorker(processed.Worker); //Bank Details
id = worker.TransferEmployeeCode;
EmployeeID = strKeep(id,’0123456789′);
sdate = processed.PayrollDt;
pdate = any2date(sdate);
PayrollDate = date2str( pdate,213,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator::Slash,DateYear::Digits4);

BankGroup = BankGroup::find(bank.BankGroupId);
masterCurrency = HcmEmploymentEmployee::findByEmployment(HcmEmployment::findByWorker(processed.Worker).RecId).PayrollCurrency;
//Bank Code
if(BankGroup.BankGroupId == “SCB”)
bankCode = “BT”;
CurrencyTo = “BHD”;
currencyfrom = “BHD”;
else if((curext() == “YME”) || (curext() == “YME”))
bankCode = “RTGS”;
CurrencyTo = masterCurrency;
currencyfrom = “BHD”;
bankCode = “TT”;
CurrencyTo = masterCurrency;
currencyfrom = masterCurrency;


IBANACC = strFmt(“%1%2″,bank.RegistrationNum,bank.AccountNum);
netSalary = round(processed.NetSalary, 0.01);
line = [‘P’,bankCode,’ON,’,EmployeeID,”,’BH’,’MAN’,’3201612339201′,PayrollDate,worker.name(),company.Name,’,’,BankGroup.RegistrationNum,’,,’,IBANACC,’Salary Transfer’,’,,,,,,,,,,,,,,,’,

//head count and total
bottom = [‘T’,counttoatl,net];
info(“Text file generated successfully.”);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s