Get DimensionValue From Ledger Dimension

A very common requirement is to derive the Ledger Value from a Ledger Dimension.
To meet this requirement you can use the following code snippet.
The method as input accepts two values: a rec id of the ledger dimension and the name of the dimension attribute. The function returns a string that contains the dimension value.

/// <summary>
/// Get Value by Ledger Dimension
/// </summary>
/// <param name = "_dimensionDefault">Dimension Default</param>
/// <param name = "_dimensionName">Dimension Name</param>
/// <returns>DimensionValue</returns>
private DimensionValue getValueByLedgerDimension(LedgerDimensionAccount  _dimensionDefault, Name _dimensionName)
{
        DimensionValue  res;
        DimensionAttribute dimensionAttribute = DimensionAttribute::findByName(_dimensionName);
        if (dimensionAttribute)
        {
            FieldId         fieldIdDim = DimensionAttributeValueCombination::getDimensionValueFieldId(_dimensionName);
            if (fieldIdDim)
            {
                DimensionAttributeValueCombination dimValueTable = DimensionAttributeValueCombination::find(_dimensionDefault);
                if (dimValueTable.RecId)
                {
                    res = dimValueTable.(fieldIdDim);
                }
            }
        }
   return res;
}

Lascia un commento