Thursday, 19 December 2019

to get package information through command d365

open command prompt as a admin

point to drive where application hosted. In my case it is C:

run below command.

c:\AOSService\PackagesLocalDirectory\Bin\xppbp.exe -metadata=c:\AOSService\PackagesLocalDirectory -all -model="ApplicationSuite.INTC_EXP" -xmlLog=BPCheckLog_ApplicationSuite.xml -module=ApplicationSuite -car=c:\temp\Log_ApplicationSuite.xlsx
c:\AOSService\PackagesLocalDirectory\Bin\xppbp.exe -metadata=c:\AOSService\PackagesLocalDirectory -all -model="Directory.INTC_EXP" -xmlLog=BPCheckLog_Directory.xml -module=Directory -car=c:\temp\Log_Directory.xlsx
c:\AOSService\PackagesLocalDirectory\Bin\xppbp.exe -metadata=c:\AOSService\PackagesLocalDirectory -all -model="INTC_EXP" -xmlLog=BPCheckLog_INTC_EXP.xml -module=INTC_EXP -car=c:\temp\Log_INTC_EXP.xlsx
pause

Create excel template in d365

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

class INTC_MTKOTemplate
{
    #define.ItemNumber("Item number")
    #define.ItemName("Item name")
    #define.QtyRequired("Quantity required")
    #define.Remarks("Remarks")
   
    public static void main(Args    args)
    {
        MemoryStream            memoryStream = new MemoryStream();
        INTC_MTKOTemplate       mtkoTemplate = INTC_MTKOTemplate::construct();

        mtkoTemplate.generateTemplate(memoryStream);
    }

    public static INTC_MTKOTemplate construct()
    {
        return new INTC_MTKOTemplate();
    }

    public void generateTemplate(MemoryStream   _memoryStream = new MemoryStream())
    {
        using (var package = new ExcelPackage(_memoryStream))
        {
            var                 currentRow = 1;
            var                 worksheets = package.get_Workbook().get_Worksheets();
            var                 worksheet = worksheets.Add('Template');
            var                 cells = worksheet.get_Cells();
            System.String       coloum;
            ExcelRange          cell;

            coloum = #ItemNumber;
            cell = cells.get_Item(currentRow, 1);
            cell.set_Value(coloum);
            cell = null;

            coloum = #ItemName;
            cell = cells.get_Item(currentRow, 2);
            cell.set_Value(coloum);
            cell = null;

            coloum = #QtyRequired;
            cell = cells.get_Item(currentRow, 3);
            cell.set_Value(coloum);
            cell = null;

            coloum = #Remarks;
            cell = cells.get_Item(currentRow, 4);
            cell.set_Value(coloum);
            cell = null;

            package.Save();

            file::SendFileToUser(_memoryStream, 'MTKO lines template.xlsx');
        }
    }

}

Export data to excel in d365

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

class INTC_ExpenseTemplate
{
    #define.TransactionDate("Transaction date")
    #define.ExpenseType("Expense type")
    #define.Amount("Amount")
    #define.ProjId("Project Id")
    #define.SalesTaxGroup("Sales tax group")
    #define.TaxItemGroup("Tax item group")
    #define.ReceiptNumber("Receipt number")
    #define.AdditionalInformation("Additional information")
   
    public static void main(Args  _args)
    {
        TrvExpTrans             trvExpTrans;
        TrvExpTable             trvExpTable;
        MemoryStream            memoryStream = new MemoryStream();
        INTC_ExpenseTemplate    expenseTemplate = INTC_ExpenseTemplate::construct();

        trvExpTrans     =   _args.record();
        expenseTemplate.generateTemplate(trvExpTrans.ExpNumber, memoryStream);
    }

    public static INTC_ExpenseTemplate construct()
    {
        return new INTC_ExpenseTemplate();
    }

    public void generateTemplate(TrvExpNumber  _expNum, MemoryStream   _memoryStream = new MemoryStream())
    {
        using (var package = new ExcelPackage(_memoryStream))
        {
            var                 currentRow = 1;
            var                 worksheets = package.get_Workbook().get_Worksheets();
            var                 worksheet = worksheets.Add('Template');
            var                 cells = worksheet.get_Cells();
            System.String       coloum;
            TrvExpTrans         trvExpTrans;

            OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
            System.String value = #TransactionDate;
            cell.set_Value(value);
            cell = null;

            value = #ExpenseType;
            cell = cells.get_Item(currentRow, 2);
            cell.set_Value(value);

            value = #Amount;
            cell = cells.get_Item(currentRow, 3);
            cell.set_Value(value);

            value = #ProjId;
            cell = cells.get_Item(currentRow, 4);
            cell.set_Value(value);

            value = #SalesTaxGroup;
            cell = cells.get_Item(currentRow, 5);
            cell.set_Value(value);

            value = #TaxItemGroup;
            cell = cells.get_Item(currentRow, 6);
            cell.set_Value(value);

            value = #ReceiptNumber;
            cell = cells.get_Item(currentRow, 7);
            cell.set_Value(value);

            value = #AdditionalInformation;
            cell = cells.get_Item(currentRow, 8);
            cell.set_Value(value);

            while select trvExpTrans where trvExpTrans.ExpNumber    ==  _expNum
            {
                currentRow++;
                coloum = #TransactionDate;
                cell = cells.get_Item(currentRow, 1);
                cell.set_Value(trvExpTrans.TransDate);
                cell = null;

                coloum = #ExpenseType;
                cell = cells.get_Item(currentRow, 2);
                cell.set_Value(trvExpTrans.CostType);
                cell = null;

                coloum = #Amount;
                cell = cells.get_Item(currentRow, 3);
                cell.set_Value(trvExpTrans.AmountCurr);
                cell = null;

                coloum = #ProjId;
                cell = cells.get_Item(currentRow, 4);
                cell.set_Value(trvExpTrans.ProjId);
                cell = null;

                coloum = #SalesTaxGroup;
                cell = cells.get_Item(currentRow, 5);
                cell.set_Value(trvExpTrans.TaxGroup);
                cell = null;

                coloum = #TaxItemGroup;
                cell = cells.get_Item(currentRow, 6);
                cell.set_Value(trvExpTrans.TaxItemGroup);
                cell = null;

                coloum = #ReceiptNumber;
                cell = cells.get_Item(currentRow, 7);
                cell.set_Value(trvExpTrans.ReceiptNumber);
                cell = null;

                coloum = #AdditionalInformation;
                cell = cells.get_Item(currentRow, 8);
                cell.set_Value(trvExpTrans.AdditionalInformation);
                cell = null;
            }
            package.Save();
            file::SendFileToUser(_memoryStream, 'Expense lines template.xlsx');
        }
    }

}