Developer forum

Forum » Integration » Export failed orders as Excel

Export failed orders as Excel

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

Is there any way I can export failed orders as independent files instead of cumulated in one excel file?

And by failed I mean completed (new) but failed to be synced with the ERP.

I am happy with any option. Data integration or order details.

Thank you,

Adrian


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Adrian,

if you have the Live integration you can look into OrderHandler.cs file
UpdateOrder method and check the line with:
bool createOrder = order.Complete;
then add some logic to this method or user ProcessResponse method and find the line with a call of HandleIntegrationFailure.
To generate the order xml there is a method:
var xml = new OrderXmlGenerator().GenerateOrderXml(order, new OrderXmlGeneratorSettings { AddOrderFieldsToRequest = true, AddOrderLineFieldsToRequest = true, CreateOrder = true, Beautify = true, LiveIntegrationSubmitType = SubmitType.DownloadedFromBackEnd, ReferenceName = "OrdersPut" });

Kind regards, Dmitrij

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Dmitrij,

Thank you for the response.

The code above, will export it as XML and not as Excel, right?

Thank you,
Adrian

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Adrian,
yes, as Xml. Maybe you can use Xml ->DataTable->Excel generation.
Xml to Datatable: https://stackoverflow.com/questions/7801646/xml-string-to-datatable-in-c-sharp

DataTable to Excel using EppPlus:
 

public void GenerateExcel()
        {
            FileInfo newFileInfo = new FileInfo(path + destinationPath);

            using (ExcelPackage pck = new ExcelPackage(newFileInfo))
            {
                foreach (DataTable table in setForExcel.Tables)
                {
                    List<ExcelWorksheet> workSheetsToRemove = new List<ExcelWorksheet>();
                    foreach (var worksheet in pck.Workbook.Worksheets)
                    {
                        if (worksheet.Name.Equals(table.TableName, StringComparison.OrdinalIgnoreCase))
                        {
                            workSheetsToRemove.Add(worksheet);
                        }
                    }
                    foreach (var worksheet in workSheetsToRemove)
                    {
                        pck.Workbook.Worksheets.Delete(worksheet);
                    }
                    ExcelWorksheet ws = pck.Workbook.Worksheets.Add(table.TableName);
                    ws.Cells["A1"].LoadFromDataTable(table, true);
                    if (logger != null)
                    {
                        logger.Log("Added table: " + table.TableName + " Rows: " + table.Rows.Count);
                    }
                }
                pck.Save();
                if (logger != null)
                {
                    logger.Log("Writing to " + destinationPath + " is saved and finished");
                }
            }

        }
Regards, Dmitrij

 

You must be logged in to post in the forum