Hello DAX DEV,
Here’s a simple class doing a CSV file Construction and Export in Dynamics 365
The EDTs FilePath, FileNameSave, FileNameOpen are Obsolete in AX7, So creating dialog fields to manage the file info is no longer an option.
There is a new class called File to replace file handling.
This is the whole code exporting custInvoice Info to a CSV.
Notice how easy is it to send the file to the User
Line 46: File::SendStringAsFileToUser(str _csvFileContent, str _filename);
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Begin: Felipe Nogueira - AXAPTAHUT , Dec 17th 2018 | |
class FileExporter | |
{ | |
commaStreamIo iO; | |
custInvoiceTrans custInvoiceTrans; | |
Filename filename; | |
public static void main(Args args) | |
{ | |
FileExporter fileExporter = new FileExporter(); | |
fileExporter.run(); | |
} | |
void new() | |
{ | |
iO = commaStreamIo::constructForWrite(); | |
filename = "CustInvoiceExport.csv"; | |
} | |
void run() | |
{ | |
if (Box::yesNo("Do you wish to extract Customer Invoice info to a CSV file?",DialogButton::Yes)) | |
{ | |
container header = ["Invoice number", | |
"Invoice Date", | |
"Item Id", | |
"Price", | |
"Qty", | |
"Line Amount"]; | |
iO.writeExp(header); | |
header = conNull(); | |
while select custInvoiceTrans | |
order by InvoiceId,LineNum | |
{ | |
container line = [custInvoiceTrans.InvoiceId, | |
custInvoiceTrans.InvoiceDate, | |
custInvoiceTrans.ItemId, | |
custInvoiceTrans.SalesPrice, | |
custInvoiceTrans.Qty, | |
custInvoiceTrans.LineAmount]; | |
iO.writeExp(line); | |
} | |
System.IO.Stream stream = iO.getStream(); | |
stream.Position = 0; | |
System.IO.StreamReader reader = new System.IO.StreamReader(stream); | |
str csvFileContent = reader.ReadToEnd(); | |
File::SendStringAsFileToUser(csvFileContent, filename); | |
info(strFmt("CSV file %1 Sent to user",filename )); | |
} | |
} | |
} | |
//End: Felipe Nogueira - AXAPTAHUT , Dec 17th 2018 |
Follow us and get exclusive AX DEV content weekly