Friday, April 24, 2020

Get sales price from trade agreements in D365 F&O via X++

Below is the code to get sales price from trade agreements in D365 F&O via X++.


    SalesPrice      price;
    InventDim       inventDim;
    PriceDisc       priceDisc;
    InventTable     inventTable = InventTable::find('A0001');
    CustTable       custTable   = CustTable::find('US-001');
  
    inventDim.InventSiteId      = '1';
    inventDim.InventLocationId  = '11';
    inventDim.wMSLocationId  = '11';
    inventDim = InventDim::findOrCreate(inventDim);

    PriceDiscParameters parameters =  PriceDiscParameters::construct();
    parameters.parmAccountNum(custTable.AccountNum);
    parameters.parmCurrencyCode(custTable.Currency);
    parameters.parmInventDim(inventDim);
    parameters.parmItemId(inventTable.itemid);
    parameters.parmModuleType(ModuleInventPurchSales::Sales);
    parameters.parmPriceDiscDate(systemDateGet());
    parameters.parmQty(1);
    parameters.parmUnitID('pcs');;


    priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);
      
    if(priceDisc.findPrice(custTable.PriceGroup,false))
    {
        price = priceDisc.price();
    }
    info (strFmt("Price = %1", price));


Thursday, April 2, 2020

"Object reference not set to an instance of an object" error while saving changes to an object in D365 F&O

Some times we receive error like "Object reference not set to an instance of an object" while saving changes to an object in VS.

To get rid of this error right click on the object which causes the issue and select Exclude From Project.  Then add the object again from AOT to the Project.