I was trying this code for make extraction, but take lot of time because I have lot of data, so I know that in reports in dynamics we use insert_record_set and update_record_set , for make the operation faster, but for extract data from dynamics sql to a CSV file, I don’t know if there is a way to make it faster
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 ));
}
}
}