Monday 29 January 2018

Finding MainAccountId from LedgerDimension record Id in Dynamics 365 FO.

There is a easy way to find or getting the main account number separated from LedgerDimension (RecId).

Main Account table holds the method findByLedgerDimension, by passing ledgerdimensionRecId will return the MainAccountTable. This method is available in AX 2012 as well.

public static MainAccount findByLedgerDimension(
    LedgerDimensionAccount  _ledgerDimension,
    boolean                 _forupdate = false,
    ConcurrencyModel        _concurrencyModel = ConcurrencyModel::Auto)
{
    MainAccount                         mainAccount;
    DimensionAttributeValueCombination  ledgerDimension;

    mainAccount.selectForUpdate(_forupdate);
    if (_forupdate  && _concurrencyModel != ConcurrencyModel::Auto)
    {
        mainAccount.concurrencyModel(_concurrencyModel);
    }

    // Assumes that the main account is properly denormalized on the ledger dimension to avoid joining to the level value
    select firstonly * from mainAccount
        exists join ledgerDimension where
            ledgerDimension.MainAccount == mainAccount.RecId &&
            ledgerDimension.RecId == _ledgerDimension;

    return mainAccount;
}

Calculate ledger balance by dimension set in X++ in AX2012/Dynamics 365 FO

There are a variety of ways users can view balances in the general ledger. Some of the most common options are: 1. Trial balance 2. Financia...