Extraction from dynamics 365 take a lot of time

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 ));
    }
}

}

1 Like

The standard data management uses a more efficient way of extracting data than your custom code. On the other hand, it has some overhead, because it supports many more features. Try it on the same data and measure times in both cases.

If this is regular export, you can use recurring jobs in DIXF . It can be automated by using middleware like logic apps or power automate

1 Like