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;
}

No comments:

Post a Comment

Best Practices for Troubleshooting Application Issues in D365 and Power Platform

When facing application issues, it’s important to systematically troubleshoot before reaching out for support.  Follow these steps to ensure...