Call the below method for file generation
public void accGenerateCheckFile()
{
#define.delimiter('|')
container cont;
str fileContent, dateStr, timeStr;
UtcDateTime creationDateTimeInUserTimeZone;
date creationDate;
TimeOfDay creationTime;
Filename fileName;
TextStreamIo io = TextStreamIo::constructForWrite();
io.outFieldDelimiter('|');
//Export file header
//Export records
cont = conNull();
cont = ['AX2009', 'Ax2012', 'D365FO'];
io.writeExp(cont);
}
//Prepare file name
creationDateTimeInUserTimeZone = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::utcNow(), DateTimeUtil::getUserPreferredTimeZone());
creationDate = DateTimeUtil::date(creationDateTimeInUserTimeZone);
//creationTime = DateTimeUtil::time(creationDateTimeInUserTimeZone);
dateStr = date2str(creationDate,213,DateDay::Digits2,DateSeparator::None,DateMonth::Digits2,DateSeparator::None,DateYear::Digits4);
//timeStr = num2str( creationTime div 3600,2,0,0,0)+ num2Str0(creationTime mod 3600 div 60,2,0,0,0) + num2Str0(creationTime mod 3600 mod 60,2,0,0,0);
fileName = dateStr + '.txt';
// Set stream
System.IO.Stream stream = io.getStream();
stream.Position = 0;
// Set stream reader
System.IO.StreamReader sReader = new System.IO.StreamReader(stream);
// Set file contentn string
fileContent = sReader.ReadToEnd();
// Save file
File::SendStringAsFileToUser(fileContent, fileName);
}
Note: If the requirement is to export CSV then use CommaStreamIo instead TextStreamIo