DimensionStorage::getDefaultAccountForMainAccountNum()

Hi! I am struggling with Dynamics AX 2012 now. It consume a lot of energy =)
I have fond one issue that should be changed in standard Dynamics AX 2012 (for my point of view).

Different Dynamics AX entities (companies) could have the same name of main accounts.

If it is required to convert main account name to ledger dimension id the DimensionStorage::getDefaultAccountForMainAccountNum() method is used.
This method contains the following code:

select recId from MainAccount where mainAccount.MainAccountId == _mainAccountNum;
return DimensionStorage::getDefaultAccount(mainAccount.RecId);

We can see that where clause doesn’t contain the entity identification. So if different Dynamics AX entities (companies) have same main accounts then “select” returns any of them.
This will lead to different errors because method is not convert main account name to ledger dimension id as assumed.

The select statement should be changed to the following:

select recId from mainAccount
where mainAccount.MainAccountId == _mainAccountNum
join ledger
where ledger.ChartOfAccounts == mainAccount.LedgerChartOfAccounts
join companyInfo
where companyInfo.RecId == ledger.PrimaryForLegalEntity &&
companyInfo.DataArea == curext();

Hope Microsoft team find this topic to check the solution.
All the best 😉