Code upgrade snippets from AX2009 to AX2012 and D365FO

InventDimSearch

In Microsoft Dynamics AX 2009, the InventDimSearch class was used to get information about the
inventory dimension setup. This class has been deleted and several new classes have been
implemented to make it possible to get information about the dimension setup.

In order to determine whether a dimension for a specific field is active in Microsoft Dynamics AX 2009,
the following code could be used:

InventDimSearch inventDimSearch = new InventDimSearch();
InventDimGroupId dimGroupId = InventTable::find(ItemId). DimGroupId;
;
if (inventDimSearch.findActive(dimGroupId,fieldNum(InventDim,wmsPalletId)))
{
    info(strFmt("The palletId dimension is active for dimension group %1",dimGroupId));
}

In Microsoft Dynamics AX 2012 & D365FO, this can be achieved by the following code:

InventTable inventTable;
InventDimGroupSetup inventDimGroupSetup;
InventDimGroupFieldSetup inventDimGroupFieldSetup;
 
inventDimGroupSetup = InventDimGroupSetup::newInventTable(inventTable);
inventDimGroupFieldSetup =
inventDimGroupSetup.getFieldSetup(fieldNum(InventDim,WMSPalletId));
 
if (inventDimGroupFieldSetup.isActive())
{
    info(strFmt("The palletId dimension is active for dimension group
    %1",inventDimGroupSetup.getStorageDimensionGroup()));));
}

EmplTable

In Microsoft Dynamics AX 2009

In Microsoft Dynamics AX 2012 & D365FO , we have HcmWorkerHelper class which gives much information about worker such as department, primary position, current legal entity and so on.

HcmWorkerRecId   hcmWorkerRecId =  HcmWorker::userId2Worker(curUserId());
HcmPositionRecId hcmPositionRecId = HcmWorkerHelper::getPrimaryPosition(hcmWorkerRecId);
 
HcmWorker currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker());
OMOperatingUnit department = HcmWorkerHelper::getPrimaryDepartment(currentWorker.RecId);
 
HcmWorker currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker());
CompanyInfo legalEntity = HcmWorkerHelper::getLegalEntity(currentWorker.RecId);

Unit converter

In Microsoft Dynamics AX 2009

UnitConvert::qty(Qty,FromUnitId,ToUnitId,ItemId);
Unit::decimals()

In Microsoft Dynamics AX 2012 & D365FO

UnitOfMeasureConverter::convert(_salesQty,  
               UnitOfMeasure::unitOfMeasureIdBySymbol(_inventUnit),  
               UnitOfMeasure::unitOfMeasureIdBySymbol(_salesUnit),  
               NoYes::Yes,  
               InventTable::itemProduct(_itemId),  
               NoYes::Yes);  
UnitOfMeasure::unitOfMeasureDecimalPrecision(UnitOfMeasure::unitOfMeasureIdBySymbol(unitID));

CompanyInfo

In Microsoft Dynamics AX 2009

CompanyInfo::standardCurrency()
CompanyInfo::find().CurrencyCode

In Microsoft Dynamics AX 2012 & D365FO

Ledger::accountingCurrency(CompanyInfo::current())

Currency

In Microsoft Dynamics AX 2009

Currency::amountCur2MST(*)
Currency::Amount()
Currency::exchRate(*)
Currency::exchRateSecond(*)

In Microsoft Dynamics AX 2012 & D365FO

CurrencyExchangeHelper::amountCur2MST(*)
CurrencyExchangeHelper::amount(*);
ExchangeRateHelper::exchRate(*)
ExchangeRateHelper::exchRateSecond()