Tuesday, 4 September 2018



    


Button Enable/Disable in D365



            There are 4 button added in sales table form
This will enable / disable according status.
Solution : sales table form-> event-> initialized (post event)->copy event handler
Create class


class Aks_ManuItemHide
{
   

  

   

  // button enable and disable in sales table form
    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormEventHandler(formStr(SalesTable), FormEventType::Initialized)]
    public static void SalesTable_OnInitialized(xFormRun sender, FormEventArgs e)
    {
        Common common1 = sender.args().record();
        SalesTable SalesTable;
        CustConfirmJour   CustConfirmJour;
        WMSPickingRoute    WMSPickingRoute;
        CustPackingSlipJour  CustPackingSlipJour;
        CustInvoiceJour     CustInvoiceJour;
           
        SalesTable = common1;
     
        FormControl    God_buttonJournalConfirmation           = sender.design(0).controlName("God_buttonJournalConfirmation");
        FormControl    God_buttonJournalPickingList            = sender.design(0).controlName("God_buttonJournalPickingList");
        FormControl    God_buttonJournalPackingSlip            = sender.design(0).controlName("God_buttonJournalPackingSlip");
        FormControl    God_buttonJournalInvoice                = sender.design(0).controlName("God_buttonJournalInvoice");
        select CustConfirmJour
            where CustConfirmJour.SalesId == SalesTable.SalesId;
        if(CustConfirmJour)
        {
            God_buttonJournalConfirmation.enabled(true);
        }
        else
        {
            God_buttonJournalConfirmation.enabled(false);
        }

        select WMSPickingRoute
            where WMSPickingRoute.transRefId == SalesTable.SalesId;
        if(WMSPickingRoute)
        {
            God_buttonJournalPickingList.enabled(true);
        }
        else
        {
            God_buttonJournalPickingList.enabled(false);
        }
        select CustPackingSlipJour
           where  CustPackingSlipJour.SalesId == SalesTable.SalesId;
        if(CustPackingSlipJour)
        {
            God_buttonJournalPackingSlip.enabled(true);
        }
        else
        {
            God_buttonJournalPackingSlip.enabled(false);
        }
        select CustInvoiceJour
            where CustInvoiceJour.SalesId == SalesTable.SalesId;
        if(CustInvoiceJour)
        {
            God_buttonJournalInvoice.enabled(true);
        }
        else
        {
            God_buttonJournalInvoice.enabled(false);
        }


    }

}





Thanks
Akshay


How to use Form Data source Activeted method in D365




Here i am going to write code in Active event of form-> data source.

SalesTable-> DS->salesLine-> event-> copy event of Activated.

1. create class.
2. paste copied event in class.
3. class Data source by
        FormDataSource      fds = sender.formRun().dataSource("SalesLine");
        SalesLine           salesline = fds.cursor();

4. put logic according you.
       








class Aks_SODSSLActivated
{
   
   

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    [FormDataSourceEventHandler(formDataSourceStr(SalesTable, SalesLine), FormDataSourceEventType::Activated)]
    public static void SalesLine_OnActivated(FormDataSource sender, FormDataSourceEventArgs e)
    {
       
        real                             Amount,amt1;
        Tax                              tax;
       
      
        FormDataSource      fds = sender.formRun().dataSource("SalesLine");
        SalesLine           salesline = fds.cursor();
       

       
        if(salesline.LineDisc > 0 || salesline.LinePercent >0)
        {
            fds.object(fieldNum(SalesLine,Aks_givenDiscount)).allowEdit(false);
          
            salesline.Aks_givenDiscount =0;
        }
         
        else
        {
          
            fds.object(fieldNum(SalesLine,Aks_givenDiscount)).allowEdit(true);
        }
      
            }

}






Thanks
Akshay


How to use Field Modified in Datasource in ax D365

How to use Field Modified in Datasource in ax D365

Here we are going to use Modified in item field in form datasource. 
form-> salestable -> Ds-> salesline -> itemid-> event-> modified -> copy event.

create new class
Paste event in this class

Call  datasource.

 FormDataSource      SalesLine_ds   = sender.dataSource();

 SalesLine           SalesLine      = SalesLine_ds.cursor();







class Aks_NetAmtBasedonGivenDisc
{
   
       [FormDataFieldEventHandler(formDataFieldStr(SalesTable, SalesLine, ItemId), FormDataFieldEventType::Modified)]

    public static void ItemId_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
    {
        EcoResCategory                   ecoResCategory;
        InventTable                      inventTable;
        EcoResProductCategory            ecoResProductCategory;
        EcoResCategoryHierarchy          ecoResCategoryHierarchy;
        InventOnhand                     inventOnHand;
        InventDimParm                    inventDimParm;
        InventQty                        availQty;
        InventDim                        inventdim;
        //ItemId                           itemid;
        SalesTable                       salestable;
        real                             Amount,amt1;
        Tax                              tax;

      
        FormDataSource      SalesLine_ds   = sender.dataSource();
        SalesLine           SalesLine      = SalesLine_ds.cursor();
        ItemId              ItemId         = sender.getValue(0);
   
        select InventTable
            where inventTable.ItemId == ItemId;//SalesLine.ItemId;
          
        while select ecoResProductCategory
            where ecoResProductCategory.Product == inventTable.Product
           join ecoResCategoryHierarchy
            where ecoResCategoryHierarchy.RecId == ecoResProductCategory.CategoryHierarchy
           && ecoResCategoryHierarchy.Name == "Retail Product Category"
        {
            select ecoResCategory
                where ecoResCategory.RecId == ecoResProductCategory.Category;
           
            SalesLine.God_AllowedDiscount = ecoResCategory.GOD_AllowedDiscount;
        }
        Amount = Tax::calcTaxAmount(SalesLine.TaxGroup,SalesLine.TaxItemGroup,systemDateGet(),SalesLine.CurrencyCode,SalesLine.LineAmount,TaxModuleType::Sales);
     
        SalesLine.Aks_TotalAmoutWithVAT = SalesLine.LineAmount + Amount;
 


    }
 }






Thanks
Akshay



How to modify Table Existing method in D365


This method is use to modify existing method of table , here i am going to use 
Sales Line method initfromSalesQuotationLine.

in this case i am going to use Chain of Command. this is very useful Technic to modify existing mathod.

1. create new class with _Extension
2. use Extensionof for your table which you want to modify
3. use this mathod according you REQUIREMENT. 

Check the method in table

[ExtensionOf(tableStr(SalesLine))]


final class AksExtensiontablemath_Extension
{
   
    // this mathod is used to fatch data from sales quotation table to sales line after SQ confirmation
    public void initFromSalesQuotationLine(SalesQuotationLine      _salesQuotationLine)
    {
        next initFromSalesQuotationLine(_salesQuotationLine);
        this.Aks_givenDiscount = _salesQuotationLine.Aks_GivenDiscount;
    }

}






Thanks
Akshay



How to make display method in D365



1. Create new Class with Extension
2. Write your method with Cache syntax.
3. take new field in form 
4. give Datasource and datamathod as classname::method name in Field properties
5. yes to Cache Data method in Field properties


public static class DisplayVATAmount_Extension
{

    // display method to check available qty onhand by item with warehouse
    public static display real QtyAvail(SalesLine _this)
    {
        InventOnhand                     inventOnHand;
        InventDimParm                    inventDimParm;
        InventQty                        availQty;
        InventDim                        inventdim;
       

        inventDim.InventLocationId = inventDim::find(_this.InventDimId).InventLocationId;
    // inventDim.InventLocationId = inventDim::find(SalesLine.InventDimId).InventSiteId;
   
    inventDimParm.initFromInventDim(inventDim);
       
        inventOnHand = inventOnHand::newParameters(_this.ItemId,inventDim,inventDimParm);
       
    availQty = inventOnHand.availPhysical();
    return availQty;
    }
 }

Data mathod : DisplayVATAmount_Extension::QtyAvail




Thanks
Akshay

Friday, 20 July 2018



Movement Journal Uploading using Excel x++ in Ax 2012






static void Aks_CreateMovementJournal(Args _args)
{
    Dialog                      dialog;
    Filename                    filename;
    DialogField                 dialogFilename;
    //To filter the files while selecting
    container                   conFilter = ["Microsoft Excel 97-2003 Worksheet (.xls)" ,"*.xlsx"];
    SysExcelApplication                 application;
    SysExcelWorkbooks                   workbooks;
    SysExcelWorkbook                    workbook;
    SysExcelWorksheets                  worksheets;
    SysExcelWorksheet                   worksheet;
    SysExcelCells                       cells;
    COMVariantType                      type;
    int                                 row=1;
    ItemId                           itemId;
    InventJournalTable      journalTable;
    InventJournalTableData  journalTableData;
    InventJournalTrans      inventJournalTrans;
    InventDim               toInventDim,frominventDim;
    TransDate                   transDate;
    InventQtyJournal            inventQtyJournal;
    InventBatchId               inventBatchId, toinventBatchId;
    InventDimId                 inventDimId;
    InventSiteId                inventSiteId,toinventSiteId;
    WMSLocationId               wMSLocationId,towMSLocationId;
    InventLocationId            inventLocationId,toinventLocationId;
    EcoResItemColorName     inventcolorid;
    InventSerialId  inventSerialId;
    real         CostAmount;
    real   costprice;
    container  ledgerDimensions;

    container   accountCon;
    int         dimCount;
    str 20 mainAccount;
 

   // LedgerDimensionAccount  LedgerDimensionAccount;
   
    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    dialog = new dialog();
    dialog.caption("select a file");
    //dialogFilename      =   dialog.addField(typeId(FilenameOpen));
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    //To filter the files while selecting
    dialog.filenameLookupFilter(conFilter);
    dialog.run();
    if(dialog.closedOk())
    {
        filename = dialogFileName.value();
    }
    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    do
{
        row++;
                transDate                           = cells.item(row,1).value().date();
                itemId                             = cells.item(row,2).value().bStr();
               // inventQtyJournal                    = cells.item(row,3).value().double();
   
               
                inventSiteId=  cells.item(row,3).value().bStr();
                inventLocationId =  cells.item(row,4).value().bStr();
                inventcolorid = cells.item(row,5).value().bStr();
                inventBatchId = cells.item(row,6).value().bStr();
                wMSLocationId = cells.item(row,7).value().bStr();
                inventSerialId  = cells.item(row,8).value().bStr();
                inventQtyJournal   = cells.item(row,9).value().double();
                costprice =   cells.item(row,10).value().double();
                CostAmount = cells.item(row,11).value().double();
                mainAccount = cells.item(row,12).value().bStr();

                           Ttsbegin;
        inventJournalTrans.clear();
    inventJournalTrans.JournalId      = 'AKS-000232';
    inventJournalTrans.JournalType    = InventJournalType::Movement;
    inventJournalTrans.TransDate      = transDate;
    inventJournalTrans.ItemId         = itemId;
    inventJournalTrans.Qty            = inventQtyJournal ;

        inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId), False, False);
   // Dimensions From which the transfer performs
    frominventDim.InventSiteId = inventSiteId;
    frominventDim.InventLocationId =inventLocationId;
    frominventDim.inventBatchId = inventBatchId;
    frominventDim.wMSLocationId = wMSLocationId;
    frominventDim.InventColorId = inventcolorid;
    frominventDim.inventSerialId =inventSerialId;
   
    inventJournalTrans.InventDimId = InventDim::findOrCreate(frominventDim).inventDimId;
    inventJournalTrans.CostPrice = costprice;
    inventJournalTrans.CostAmount = CostAmount;
   
    accountCon = ["MainAccount", mainAccount];
    inventJournalTrans.LedgerDimension = AxdDimensionUtil::getLedgerAccountId(accountCon);

    inventJournalTrans.insert();

ttsCommit;
             // info(strfmt("%1",inventJournalTrans.ItemId));
        type = cells.item(row+1, 1).value().variantType();
        } while(type != COMVariantType::VT_EMPTY);


    workbooks.close();
    application.quit();
    info("Operation/Processing Completed");
}



Thanks,
Akshay