How to Get Dimension Values from Ledger Dimension in D365 F&O (X++)

What is a Ledger Dimension ?

In D365 F&O, a Ledger Dimension is a RecId that points to a combination of financial dimension values stored in the system. When a user selects a ledger account with dimensions (e.g., 110110-CC001-DEPT02), the system stores this combination and assigns it a unique RecId, that's your Ledger Dimension.

The actual dimension values behind this RecId are stored across framework tables, which is why you need a specific query to pull them out.

Here is the complete static method:

public static str getLedDimValue(RecId _ledgerDimension, str _dimName)
{
    DimensionAttributeLevelValueAllView dimAttrLevelAll;
    DimensionAttribute dimAttribute;

    // Join to find specific dimension name and its display value
    select DisplayValue
    from dimAttrLevelAll
    join dimAttribute
    where dimAttribute.RecId == dimAttrLevelAll.DimensionAttribute
    && dimAttrLevelAll.ValueCombinationRecId == _ledgerDimension
    && dimAttribute.Name == _dimName;

    return dimAttrLevelAll.DisplayValue;
}

How to Use It

Place this method inside a class (e.g., a utility or helper class like DimensionHelper). Then call it from anywhere in your X++ code like this:


RecId ledgerDim = ledgerJournalTrans.LedgerDimension;

str costCenter  = DimensionHelper::getLedDimValue(ledgerDim, "CostCenter");

str department  = DimensionHelper::getLedDimValue(ledgerDim, "Department");

info(strFmt("Cost Center: %1, Department: %2", costCenter, department));


If you found this helpful, feel free to share it or leave a comment below. Happy coding in D365! 🚀

Comments