‘findItemPriceAgreement’ is obsolete. Use the instance method PriceDisc.findPrice instead.

This is an example of a code upgrade from Ax 2012 R3 to D365FO. It is not so hard to figure out but might save 30-60 minutes for someone else out there. PriceDisc::findItemPriceAgreement(…) call needs to be replaced by  priceDisc.findPrice(…) as stated in the compilation error, but ‘findPriceAgreement’ has many parameters while ‘findPrice’ has only one. The solution is to use the ‘PriceDiscParameters’ class. Using its ‘parm’ methods, set the parameters that were before separate parameters of the ‘findPriceAgreement’ static method, after that call ‘PriceDisc::newFromPriceDiscParameters(priceDiscParameters)’ to create an intance of PriceDisc See an example below:

AX2012 code:

private PriceCur getPurchasePrice(ItemId _item, ReqQty _reqQty, TransDate _priceDate)
{
    PriceCur            purchPrice = 0;
    InventTableModule   inventModule;
    TransDate           priceDate  = _priceDate;
    PriceDisc           priceDisc;
    
    if(jjeParameters.TradePriceByDueDate == NoYes::No)
    {
        priceDate = SystemDateGet();
    }
    inventModule = InventTableModule::find(_item, ModuleInventPurchSales::Purch);
    [ purchPrice ] = PriceDisc::findItemPriceAgreement(inventModule.ModuleType, _item, inventDim, inventModule.UnitId, priceDate, _reqQty, vendTable.AccountNum, vendTable.Currency, '');

    return purchPrice;
}

Code upgraded to D365FO:

private PriceCur getPurchasePrice(ItemId _item, ReqQty _reqQty, TransDate _priceDate)
{
    PriceCur            purchPrice = 0;
    InventTableModule   inventModule;
    TransDate           priceDate  = _priceDate;
    PriceDisc           priceDisc;
    PriceDiscParameters parameters = PriceDiscParameters::construct();

    if(jjeParameters.TradePriceByDueDate == NoYes::No)
    {
        priceDate = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());
    }
    inventModule = InventTableModule::find(_item, ModuleInventPurchSales::Purch);

    parameters.parmModuleType(ModuleInventPurchSales::Purch);
    parameters.parmItemId(_item);
    parameters.parmInventDim(inventDim);
    parameters.parmUnitID(inventModule.UnitId);
    parameters.parmPriceDiscDate(priceDate);
    parameters.parmQty(_reqQty);
    parameters.parmAccountNum(vendTable.AccountNum);
    parameters.parmCurrencyCode(vendTable.Currency);
    priceDisc = PriceDisc::newFromPriceDiscParameters(parameters);

    priceDisc.findPrice('');
        
    return priceDisc.price();
}

https://github.com/PeterProkopecz/AX/tree/master/D365FO_Upgrade_PriceDisc_FindPrice

Leave a Reply

Your email address will not be published. Required fields are marked *