Excel Export in X++ D365

Hi,

Excel Export in X++ D365

Sample code

using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;

class MisallocatedItemLocationsCS
{
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {
       
        SalesLine  salesline;
        InventSum inventSum,inventSum1;
        InventDim inventDim;
        WHSInventFixedLocation  whsInventFixedLocation,whsInventFixedLocationOther;
        InventOnhand inventOnHand;
        InventDimParm inventDimParm;
        ItemId itemid;
        WMSLocationId correctwmsLocationId;
        WMSLocationId misallocatedwmsLocationId;

        MemoryStream memoryStream = new MemoryStream();

        using (var package = new ExcelPackage(memoryStream))
        {
            var currentRow = 1;

            var worksheets = package.get_Workbook().get_Worksheets();
            var CustTableWorksheet = worksheets.Add("MisallocatedItemLocations");
            var cells = CustTableWorksheet.get_Cells();
            OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
            System.String value = "Item Number";
            cell.set_Value(value);
            cell = null;
            value = "Fixed Location for this Item";
            cell = cells.get_Item(currentRow, 2);
            cell.set_Value(value);
            value = "Inventory Located in another pick Location";
            cell = cells.get_Item(currentRow, 3);
            cell.set_Value(value);
            value = "Batch";
            cell = cells.get_Item(currentRow, 4);
            cell.set_Value(value);
            value = "License plate";
            cell = cells.get_Item(currentRow, 5);
            cell.set_Value(value);
            value = "Quantity";
            cell = cells.get_Item(currentRow, 6);
            cell.set_Value(value);
         
                //InventSum::find(
                while select * from inventSum Order by inventSum.ItemId
                {
                    if(InventTable::find(inventSum.ItemId).Custom_FixedLocation ==NoYes::Yes  )

                    {
                        inventDim =InventDim::find(inventSum.InventDimId);

                        if(inventDim.wMSLocationId)
                    {
                        if(inventSum.physicalInventCalculated() > 0)
                        {
                            select firstonly whsInventFixedLocation where whsInventFixedLocation.ItemId == inventSum.ItemId ;

                            if(inventDim.wMSLocationId != whsInventFixedLocation.WMSLocationId)
                            {

                                select firstonly   whsInventFixedLocationOther
                                where whsInventFixedLocationOther.WMSLocationId ==inventDim.wMSLocationId;

                                if(whsInventFixedLocationOther)
                                {
                                    //    if( correctwmsLocationId !=whsInventFixedLocation.wMSLocationId &&   misallocatedwmsLocationId != whsInventFixedLocationOther.WMSLocationId && itemid !=whsInventFixedLocation.ItemId)
                                    //{
                                    correctwmsLocationId =whsInventFixedLocation.wMSLocationId;
                                    misallocatedwmsLocationId = whsInventFixedLocationOther.WMSLocationId;
                                    itemid =whsInventFixedLocation.ItemId;

                                    currentRow ++;
                                    cell = null;

                                    cell = cells.get_Item(currentRow, 1);
                                    cell.set_Value(whsInventFixedLocation.ItemId);
                                    cell = null;

                                    cell = cells.get_Item(currentRow, 2);
                                    cell.set_Value(correctwmsLocationId);

                                    cell = cells.get_Item(currentRow, 3);
                                    cell.set_Value(misallocatedwmsLocationId);

                                    cell = cells.get_Item(currentRow, 4);
                                    cell.set_Value(inventDim.inventBatchId );

                                    cell = cells.get_Item(currentRow, 5);
                                    cell.set_Value(inventDim.LicensePlateId  );

                                    cell = cells.get_Item(currentRow, 6);
                                    cell.set_Value(inventSum.physicalInventCalculated());

                                    //  info(whsInventFixedLocation.ItemId + ' Item wrongly placed in ' + whsInventFixedLocationOther.WMSLocationId  + ' Correct fixed location is ' + whsInventFixedLocation.wMSLocationId);
                                 
                                    // }
                                }
                            }
                        }
                    }
                    }
                }
         
            package.Save();
            file::SendFileToUser(memoryStream, "MisallocatedItemLocations");
         
        }
}
}


Reference

Reference

Comments

  1. Really good information to show through this blog. I really appreciate you for all the valuable information that you are providing us through your blog.
    D365 Finance and Operations Online Training

    ReplyDelete

Post a Comment