{"id":663,"date":"2023-12-15T21:45:13","date_gmt":"2023-12-15T13:45:13","guid":{"rendered":"https:\/\/live-d365fo.pantheonsite.io\/?p=663"},"modified":"2024-02-04T16:01:49","modified_gmt":"2024-02-04T08:01:49","slug":"code-upgrade-snippets-from-ax2009-to-ax2012-and-d365fo","status":"publish","type":"post","link":"https:\/\/dev-d365fo.pantheonsite.io\/code-upgrade-snippets-from-ax2009-to-ax2012-and-d365fo\/","title":{"rendered":"Code upgrade snippets from AX2009 to AX2012 and D365FO"},"content":{"rendered":"\n

InventDimSearch <\/h2>\n\n\n\n

In Microsoft Dynamics AX 2009, the InventDimSearch <\/strong>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.<\/p>\n\n\n\n

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

\nInventDimSearch inventDimSearch = new InventDimSearch();\nInventDimGroupId dimGroupId = InventTable::find(ItemId). DimGroupId;\n;\nif (inventDimSearch.findActive(dimGroupId,fieldNum(InventDim,wmsPalletId)))\n{\n    info(strFmt(\"The palletId dimension is active for dimension group %1\",dimGroupId));\n}\n<\/pre>\n\n\n\n

In Microsoft Dynamics AX 2012 & D365FO, this can be achieved by the following code:<\/p>\n\n\n\n

\nInventTable inventTable;\nInventDimGroupSetup inventDimGroupSetup;\nInventDimGroupFieldSetup inventDimGroupFieldSetup;\n\ninventDimGroupSetup = InventDimGroupSetup::newInventTable(inventTable);\ninventDimGroupFieldSetup =\ninventDimGroupSetup.getFieldSetup(fieldNum(InventDim,WMSPalletId));\n\nif (inventDimGroupFieldSetup.isActive())\n{\n    info(strFmt(\"The palletId dimension is active for dimension group\n    %1\",inventDimGroupSetup.getStorageDimensionGroup()));));\n}\n<\/pre>\n\n\n\n

EmplTable<\/h2>\n\n\n\n

In Microsoft Dynamics AX 2009<\/p>\n\n\n\n

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.<\/p>\n\n\n\n

\nHcmWorkerRecId   hcmWorkerRecId =  HcmWorker::userId2Worker(curUserId());\nHcmPositionRecId hcmPositionRecId = HcmWorkerHelper::getPrimaryPosition(hcmWorkerRecId);\n\nHcmWorker currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker());\nOMOperatingUnit department = HcmWorkerHelper::getPrimaryDepartment(currentWorker.RecId);\n\nHcmWorker currentWorker = HcmWorker::find(HcmWorkerLookup::currentWorker());\nCompanyInfo legalEntity = HcmWorkerHelper::getLegalEntity(currentWorker.RecId);\n<\/pre>\n\n\n\n

Unit converter<\/h2>\n\n\n\n

In Microsoft Dynamics AX 2009<\/p>\n\n\n\n

\nUnitConvert::qty(Qty,FromUnitId,ToUnitId,ItemId);\nUnit::decimals()\n<\/pre>\n\n\n\n

In Microsoft Dynamics AX 2012 & D365FO <\/p>\n\n\n\n

\nUnitOfMeasureConverter::convert(_salesQty,  \n               UnitOfMeasure::unitOfMeasureIdBySymbol(_inventUnit),  \n               UnitOfMeasure::unitOfMeasureIdBySymbol(_salesUnit),  \n               NoYes::Yes,  \n               InventTable::itemProduct(_itemId),  \n               NoYes::Yes);  \nUnitOfMeasure::unitOfMeasureDecimalPrecision(UnitOfMeasure::unitOfMeasureIdBySymbol(unitID));\n<\/pre>\n\n\n\n

CompanyInfo<\/h2>\n\n\n\n

In Microsoft Dynamics AX 2009<\/p>\n\n\n\n

\nCompanyInfo::standardCurrency()\nCompanyInfo::find().CurrencyCode\n<\/pre>\n\n\n\n

In Microsoft Dynamics AX 2012 & D365FO <\/p>\n\n\n\n

\nLedger::accountingCurrency(CompanyInfo::current())\n<\/pre>\n\n\n\n

Currency<\/h2>\n\n\n\n

In Microsoft Dynamics AX 2009<\/p>\n\n\n\n

\nCurrency::amountCur2MST(*)\nCurrency::Amount()\nCurrency::exchRate(*)\nCurrency::exchRateSecond(*)\n<\/pre>\n\n\n\n

In Microsoft Dynamics AX 2012 & D365FO <\/p>\n\n\n\n

\nCurrencyExchangeHelper::amountCur2MST(*)\nCurrencyExchangeHelper::amount(*);\nExchangeRateHelper::exchRate(*)\nExchangeRateHelper::exchRateSecond()\n<\/pre>\n","protected":false},"excerpt":{"rendered":"

InventDimSearch In Microsoft Dynamics AX 2009, the InventDimSearch class was used to get information about theinventory dimension setup. This class has been deleted and several new classes have beenimplemented 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 …<\/p>\n

Continue reading ‘Code upgrade snippets from AX2009 to AX2012 and D365FO’ »<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[10],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/posts\/663"}],"collection":[{"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":16,"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"predecessor-version":[{"id":746,"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/posts\/663\/revisions\/746"}],"wp:attachment":[{"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev-d365fo.pantheonsite.io\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}