Hi All,
I am facing another issue on exported CSV by using both classes(approaches) CommoTextIo or AsciiO. Exports works properly and correct data exporting but some of the field name(header) exported as blank. If i use condition dictfield.isSql() in my code; then those blank header fields not exporting but i should be.
For example, i have exported data from PurchLine table using above mentioned code. Exports works but fields(PDSCWQTY, PDACWREMAINNVENTFINANCIAL, PDACWREMAINNVENTPHYSICAL) names(header) are exported as blank values.
I have tried the same in our local AX environment with same code, here field names are exporting properly. I have no idea what causing this issue. Can you suggest me any of approches to overcome this issue?
Please find highlighted screenshot and code which i used to export the data
Code starts here ---------------------------------------------------------------------------------------------------------->
[SysEntryPointAttribute(false)]
public void processOperation(exportCSV _contract)
{
#File
Common tableBuffer;
DictField dictField;
DictTable dictTable;
FieldId fieldId;
FileName fileName;
TableName tableName;
date resultDate;
utcDateTime dateTimeResult;
boolean recordsExist;
int i,j,countTable,executedTable;
container line,line2;
boolean recordExist= false;
FileIOPermission permission;
Days numberDays;
MAX_TablesToExportCSV tablesToExportCSV, tablesToExportCSV2;
str nameOfTable,pathToStore;
MAX_CSVExportPath documentPath;
AsciiIo asci;
str replaceUTC;
int check;
CommoTextIo commoTextIo;
;
countTable = 0;
executedTable = 0;
check = 0;
numberDays = _contract.parmNoofDays();
resultDate = today()-numberDays;
dateTimeResult= DateTimeUtil::newDateTime(resultDate, 0);
select firstOnly documentPath;
if(documentPath)
{
pathToStore = documentPath.CSVFilePath;
}
else
{
throw error (‘Set up file path to store file’);
}
select firstOnly tablesToExportCSV2;
if(!tablesToExportCSV2)
throw error(‘Add one or more tables in the master’);
while select tablesToExportCSV order by tablesToExportCSV.ListOfTables asc where tablesToExportCSV.Export == NoYes::Yes
{
nameOfTable = tablesToExportCSV.ListOfTables;
tableName = nameOfTable;
dictTable = new dictTable(tableName2Id(tableName));
fieldId = dictTable.fieldNext(0);
tableBuffer = dictTable.makeRecord();
select crossCompany tableBuffer where (tableBuffer.createdDateTime >= dateTimeResult) || (tableBuffer.modifiedDateTime >= dateTimeResult) ;
fileName = pathToStore + ‘\’ + tableName + ‘.csv’;
permission = new FileIOPermission(fileName, #io_write);
permission.assert();
commoTextIo= new CommoTextIo(fileName ,#io_write);
commoTextIo.outFieldDelimiter(’|’);
for( i =1; i <= dictTable.fieldCnt(); i++)
{
dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(i));
line += [ dictField.name(i) ];
}
commoTextIo.write(line);
line = ConNull();
while select crossCompany tableBuffer where (tableBuffer.createdDateTime >= dateTimeResult) || (tableBuffer.modifiedDateTime >= dateTimeResult)
{
for( j =1; j <= dictTable.fieldCnt(); j++)
{
dictField = new DictField(dictTable.id(), dictTable.fieldCnt2Id(j));
if(dictField.name(j) == ‘CREATEDDATETIME’ || dictField.name(j) == ‘MODIFIEDDATETIME’ )
{
replaceUTC = DateTimeUtil::toStr(tableBuffer.(dictField.id()));
if(replaceUTC && replaceUTC != ‘’ )
{
replaceUTC = strReplace(replaceUTC, ‘T’, ’ ‘);
replaceUTC = replaceUTC + ‘.270’;
}
line2 += [ replaceUTC ];
replaceUTC = ‘’;
}
else
{
line2 += [ tableBuffer.(dictField.id()) ];
}
}
commoTextIo.write(line2);
line2 = ConNull();
recordsExist=true;
}
countTable++;
executedTable++;
CodeAccessPermission::revertAssert();
info(strFmt(‘Exported %1’,fileName));
}
}
info(strFmt(’%1 tables exported out of %2’, executedTable, countTable));
}