Tuesday, 4 September 2018



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


Wednesday, 23 May 2018



How to find Latest Date in Ax 2012 using X++


d  is a current date;

select maxOf(Aks_ValidateDate) from Aks_MetalPriceList
            where Aks_MetalPriceList.Aks_ValidateDate <= d;
   
info(strFmt("%1",Aks_MetalPriceList.Aks_ValidateDate));




Thanks,
Akshay

Wednesday, 16 May 2018



How to extract Date from utcDateTime in ax 2012 using x++


utcdateTime                 testDonedateTime1,testDonedateTime2;
utcdateTime                 testDonedateTime;
transdate                   tmpDate,tmpDate1 ;

;
testDonedateTime1 = ledgerJournalTable.createdDateTime;

testDonedateTime  = DateTimeUtil::applyTimeZoneOffset(testDonedateTime1, DateTimeUtil::getUserPreferredTimeZone());

 tmpDate = DateTimeUtil::date(testDonedateTime);

info(strfmt("Date -%1"),tmpDate));



Thanks
Akshay

Thursday, 10 May 2018


Route Version Active and approved in ax 2012 using x++



static void Aks_routeVersionApproval(Args _args)
{
RouteTable  routeTable;
    RouteVersion        routeversion;
     RouteApprove                routeApprove;
    RouteVersionApprove         routeVersionApprove;
    RouteVersionActivate        routeVersionActivate;
   
 
while select forUpdate routeversion
    where routeversion.Approved == NoYes::No
    {
       
            if (routeVersion)
            {
                routeVersionApprove = BOMRouteVersionApprove::newRouteVersion(routeVersion);
                routeVersionApprove.parmApproveRoute(true);
                routeVersionApprove.parmRemove(false);
                routeVersionApprove.parmApprover(HcmWorker::userId2Worker("akshaykupra"));//curUserId()));
                routeVersionApprove.run();

                routeVersionActivate = BOMRouteVersionActivate::newRouteVersion(routeVersion);
                routeVersionActivate.run();
            }
       
     
    }
     info("done");
   
   
}


curUserID() is ther approver user id.




Thanks
Akshay